home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2010-01-25 | 153.6 KB | 4,557 lines
if (typeof AniWeatherObj == 'undefined') { var AniWeatherObj = {}; } AniWeatherObj.Environment = function() { this.locale = ""; this.form = ""; this.ut = ""; this.ud = ""; this.us = ""; this.up = ""; this.ur = ""; this.clone = function(info) { if(typeof info == "undefined") return; this.locale = info.locale; this.form = info.form; this.ut = info.ut ; this.ud = info.ud ; this.us = info.us; this.up = info.up; this.ur = info.ur; } } AniWeatherObj.Link = function() { this.title = ""; this.link = ""; this.clone = function(info) { if(typeof info == "undefined") return; this.title = info.title; this.link = info.link; } } AniWeatherObj.LocationPara = function() { this.zipcode = ""; this.city = ""; this.county = ""; this.localId = ""; this.name = ""; this.localtime = ""; this.latitue = ""; this.longitude = ""; this.sunrise = ""; this.sunset = ""; this.zone = ""; this.clone = function(info) { if(typeof info == "undefined") return; this.zipcode = info.zipcode; this.city = info.city; this.county = info.county; this.localId = info.localId; this.name = info.name; this.localtime = info.localtime; this.latitue = info.latitue; this.longitude = info.longitude; this.sunrise = info.sunrise; this.sunset = info.sunset; this.zone = info.zone; } } AniWeatherObj.DisplayLevel = function(show, condicon, conddesc, temp) { this.show = show; this.showicon = condicon; this.showdesc = conddesc; this.showtemp = temp; } AniWeatherObj.GraphInfo = function(name, ctrlName, desc) { this.name = name; this.ctrlName = ctrlName; this.desc = desc; } AniWeatherObj.GraphLevel = function(show, width, height, animation) { this.show = show; this.width = width; this.height = height; this.animation = animation; } AniWeatherObj.ConfigPara = function() { this.buildNo = 0; this.tempUnit = 0; this.windUnit = 0; this.locInfo = []; this.defaultLocId = -1; this.weatherWidth = 0; this.weatherHeight = 0; this.fadingRatio = 0; this.fadingColor = 0; this.noticeSpan = 1; this.displayMode = 0; this.startNotice = 1; this.useMiniFrame = 0; this.displayPosition = ""; this.displayOffset = -1; this.graphPreviewWidth = 362; this.previewDelay = 600; this.displayLevel = []; this.graphLevel = []; this.parseChromeSetting = function(value) { this.initDefaultPref(); if(value.length > 0) { try{ var aryValues = value.split('&'); var len = aryValues.length; this.tempUnit = parseInt(aryValues[0]); this.buildNo = parseInt(aryValues[1]); this.defaultLocId = parseInt(aryValues[2]); var strName = unescape(aryValues[3]); var strId = aryValues[4]; this.windUnit = parseInt(aryValues[5]); var aryId = strId.split('|'); var aryName = strName.split('|'); this.locInfo = []; var len = Math.min(aryId.length, aryName.length); for(var i=0;i<len;i++) { this.locInfo.push({'name':aryName[i],'id':aryId[i]}); } if(typeof aryValues[13] == 'undefined') throw "err 01"; this.weatherWidth = parseInt(aryValues[6]); this.weatherHeight = parseInt(aryValues[7]); this.fadingRatio = parseInt(aryValues[9]); this.fadingColor = aryValues[10]; this.noticeSpan = parseInt(aryValues[11]); this.displayMode = parseInt(aryValues[12]); this.startNotice = parseInt(aryValues[13]); this.useMiniFrame = (typeof aryValues[15] == 'undefined') ? 0 : parseInt(aryValues[15]); this.graphPreviewWidth = (typeof aryValues[16] == 'undefined') ? 362 : parseInt(aryValues[16]); this.previewDelay = (typeof aryValues[17] == 'undefined') ? 500 : parseInt(aryValues[17]); if(typeof aryValues[8] != 'undefined') { var strLevels = aryValues[8]; aryLevels = strLevels.split('|'); var len = aryLevels.length; var defOp = new Array(0,0,0,0); var defCurrentOp = new Array(1,1,0,1); var aryOps = len > 0 ? aryLevels[0].split(',') : defCurrentOp; this.displayLevel['current'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = len > 1 ? aryLevels[1].split(',') : defOp; this.displayLevel['today'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = len > 2 ? aryLevels[2].split(',') : defOp; this.displayLevel['2nd'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = len > 3 ? aryLevels[3].split(',') : defOp; this.displayLevel['3rd'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = len > 4 ? aryLevels[4].split(',') : defOp; this.displayLevel['4th'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = len > 5 ? aryLevels[5].split(',') : defOp; this.displayLevel['5th'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); } if(typeof aryValues[14] != 'undefined') { var strGraphs = aryValues[14]; aryGraphs = strGraphs.split('|'); this.graphLevel = []; var len = aryGraphs.length; var defOp = new Array(0,0); var aryOps = len > 0 ? aryGraphs[0].split(',') : defOp; this.graphLevel['national'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 1 ? aryGraphs[1].split(',') : defOp; this.graphLevel['vapor'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 2 ? aryGraphs[2].split(',') : defOp; this.graphLevel['radar'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 3 ? aryGraphs[3].split(',') : defOp; this.graphLevel['uv'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 4 ? aryGraphs[4].split(',') : defOp; this.graphLevel['pop'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 5 ? aryGraphs[5].split(',') : defOp; this.graphLevel['high'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 6 ? aryGraphs[6].split(',') : defOp; this.graphLevel['air'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 7 ? aryGraphs[7].split(',') : defOp; this.graphLevel['alert'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); } }catch(e){} } } this.initDefaultPref = function() { this.tempUnit = 0; this.windUnit = 0; this.buildNo = 0; this.defaultLocId = 0; var strId = 'USNY0996|USIL0225|USCA0987|CHXX0008|FRXX0076'; var strName = 'New York, NY|Chicago, IL|San Francisco, CA|Beijing, China|Paris, France'; var aryId = strId.split('|'); var aryName = strName.split('|'); this.locInfo = []; var len = Math.min(aryId.length, aryName.length); for(var i=0;i<len;i++) { this.locInfo.push({'name':aryName[i],'id':aryId[i]}); } this.weatherWidth = 640; this.weatherHeight = 436; this.fadingRatio = 80; this.fadingColor = "#000000"; this.noticeSpan = 2; this.displayMode = 0; this.startNotice = 1; this.useMiniFrame = 0; this.displayPosition = "status-bar"; this.displayOffset = -1; this.graphPreviewWidth = 362; this.previewDelay = 600; this.displayLevel['current'] = new AniWeatherObj.DisplayLevel(1,1,0,1); this.displayLevel['today'] = new AniWeatherObj.DisplayLevel(1,1,0,1); this.displayLevel['2nd'] = new AniWeatherObj.DisplayLevel(0,1,0,1); this.displayLevel['3rd'] = new AniWeatherObj.DisplayLevel(0,1,0,1); this.displayLevel['4th'] = new AniWeatherObj.DisplayLevel(0,1,0,1); this.displayLevel['5th'] = new AniWeatherObj.DisplayLevel(0,1,0,1); this.graphLevel['national'] = new AniWeatherObj.DisplayLevel(0,0); this.graphLevel['vapor'] = new AniWeatherObj.DisplayLevel(1,0); this.graphLevel['radar'] = new AniWeatherObj.DisplayLevel(0,0); this.graphLevel['uv'] = new AniWeatherObj.DisplayLevel(0,0); this.graphLevel['pop'] = new AniWeatherObj.DisplayLevel(0,0); this.graphLevel['high'] = new AniWeatherObj.DisplayLevel(0,0); this.graphLevel['air'] = new AniWeatherObj.DisplayLevel(0,0); this.graphLevel['alert'] = new AniWeatherObj.DisplayLevel(1,0); } this.copyConfig = function(config) { this.tempUnit = config.tempUnit; this.windUnit = config.windUnit; this.buildNo = config.buildNo; this.defaultLocId = config.defaultLocId; this.locInfo = config.locInfo.slice(); this.weatherWidth = config.weatherWidth; this.weatherHeight = config.weatherHeight; this.fadingRatio = config.fadingRatio; this.fadingColor = config.fadingColor; this.noticeSpan = config.noticeSpan; this.displayMode = config.displayMode; this.startNotice = config.startNotice; this.useMiniFrame = config.useMiniFrame; this.displayPosition = config.displayPosition; this.displayOffset = config.displayOffset; this.graphPreviewWidth = config.graphPreviewWidth; this.previewDelay = config.previewDelay; this.displayLevel['current'] = config.displayLevel['current']; this.displayLevel['today'] = config.displayLevel['today']; this.displayLevel['2nd'] = config.displayLevel['2nd']; this.displayLevel['3rd'] = config.displayLevel['3rd']; this.displayLevel['4th'] = config.displayLevel['4th']; this.displayLevel['5th'] = config.displayLevel['5th']; this.graphLevel['national'] = config.graphLevel['national']; this.graphLevel['vapor'] = config.graphLevel['vapor']; this.graphLevel['radar'] = config.graphLevel['radar']; this.graphLevel['uv'] = config.graphLevel['uv']; this.graphLevel['pop'] = config.graphLevel['pop']; this.graphLevel['high'] = config.graphLevel['high']; this.graphLevel['air'] = config.graphLevel['air']; this.graphLevel['alert'] = config.graphLevel['alert']; } } AniWeatherObj.DailyWeatherInfo = function() { this.highTemp = 0; this.lowTemp = 0; this.sunrise = ""; this.sunset = ""; this.weekday = ""; this.date = ""; this.dayicon = ""; this.daycond = ""; this.daywindspeed = ""; this.daywinddir = ""; this.dayppcp = ""; this.dayhumid = ""; this.nighticon = ""; this.nightcond = ""; this.nightwindspeed = ""; this.nightwinddir = ""; this.nightppcp = ""; this.nighthumid = ""; } AniWeatherObj.GeneralWeather = function() { this.locname = ""; this.dayName = ""; this.icon = ""; this.cond = ""; this.windcond = ""; this.tempval = ""; this.vis = ""; this.humid = ""; this.uv = ""; this.ppcp = ""; this.width = ""; this.height = ""; this.fadingRatio = 0; this.fadingColor = ""; this.noticeSpan = 0; this.displayMode = 0; this.animate = false; this.moonphase = 15; this.useMiniFrame = 0; this.sunrise = ""; this.sunset = ""; this.nighticon = ""; this.nightcond = ""; this.nightppcp = ""; this.nighthumid = ""; this.nightwindcond = ""; this.nighttemp; this.graphId = ""; this.graphDesc = ""; this.graphAnimation = ""; this.daypart = ""; this.clone = function(info) { if(typeof info == "undefined") return; this.locname = info.locname; this.dayName = info.dayName; this.icon = info.icon; this.cond = info.cond; this.daypart = info.daypart; this.windcond = info.windcond; this.tempval = info.tempval; this.vis = info.vis; this.humid = info.humid; this.uv = info.uv; this.ppcp = info.ppcp; this.width = info.width; this.height = info.height; this.fadingRatio = info.fadingRatio; this.fadingColor = info.fadingColor; this.noticeSpan = info.noticeSpan; this.displayMode = info.displayMode; this.animate = info.animate; this.moonphase = info.moonphase; this.sunrise = info.sunrise; this.sunset = info.sunset; this.nighticon = info.nighticon; this.nightcond = info.nightcond; this.nightppcp = info.nightppcp; this.nighthumid = info.nighthumid; this.nightwindcond = info.nightwindcond; this.nighttemp = info.nighttemp; this.useMiniFrame = info.useMiniFrame; this.graphId = info.graphId; this.graphDesc = info.graphDesc; this.graphAnimation = info.graphAnimation; } } AniWeatherObj.CurrentWeather = function() { this.position = ""; this.temp = ""; this.feellike = ""; this.time = ""; this.condition = ""; this.icon = ""; this.windspeed = ""; this.winddir = ""; this.humid = ""; this.visible = ""; this.uvvalue = ""; this.uvlevel = ""; this.moonicon = ""; this.moondesc = ""; this.clone = function(info) { if(typeof info == "undefined") return; this.position = info.position; this.temp = info.temp; this.feellike = info.feellike; this.time = info.time; this.condition = info.condition; this.icon = info.icon; this.windspeed = info.windspeed; this.winddir = info.winddir; this.humid = info.humid; this.visible = info.visible; this.uvvalue = info.uvvalue; this.uvlevel = info.uvlevel; this.moonicon = info.moonicon; this.moondesc = info.moondesc; } } AniWeatherObj.WeatherInfo = function() { this.locationInfo = new AniWeatherObj.LocationPara(); this.currentInfo = new AniWeatherObj.CurrentWeather(); this.envInfo = new AniWeatherObj.Environment(); this.links = new Array; this.dailyInfo = new Array; this.passToday = false; this.dates = ""; this.days = ""; this.copyWeatherInfo = function(weatherInfo) { this.locationInfo.clone(weatherInfo.locationInfo); this.currentInfo.clone(weatherInfo.currentInfo); this.envInfo.clone(weatherInfo.evtInfo); this.links = weatherInfo.links.slice(); this.dailyInfo = weatherInfo.dailyInfo.slice(); this.dates = weatherInfo.dates; this.days = weatherInfo.days; this.passToday = weatherInfo.passToday; } } AniWeatherObj.ChromeRes = function() { var aryResChrome = new Object; var resID = -1; var totalItemNm; var commExt = null; var arySettings = new Array; var resIdx = 0; this.RegisterResource = function (ResName, ResValue) { if(ResName != undefined && ResName.toString().length) aryResChrome[ResName] = ResValue; }; this.GetResourceByName = function(ResName) { if(ResName != undefined && ResName.toString().length) { return (aryResChrome[ResName] == undefined) ? "" : aryResChrome[ResName]; } else return ""; }; this.prepareSettings = function(arySetting) { var strInfo = ""; arySettings.push(strInfo); } this.getResourceSet = function () { try{ // Content script commExt = chrome.extension.connect(); commExt.onMessage.addListener(function(message) { switch(message.mode) { case 0: //. Connecting // commExt.postMessage({'purpose': 'init'}); break; case 1: //. Initliazation if(message.status == 0) //. Success { commExt.postMessage({'purpose': 'set', 'name': 'General', 'value' : arySettings[resIdx]}); } break; case 2: //. Add item { break; } } }); }catch(e){/*alert(e.toString());*/} return false; } this.setResourceSet = function (aryPara) { if(!commExt) { return; } this.prepareSettings(aryPara); try{ commExt.postMessage({'purpose': 'init'}); }catch(e){} return false; } this.InitializeRes = function() { if(this.getResourceSet() == false) { this.RegisterResource('aniweather.sitebase', 'http://www.aniweather.com/'); this.RegisterResource('aniweather.mediabase', 'http://aniweather.s3.amazonaws.com/'); } }; } AniWeatherObj.IERes = function() { var aryResIE = new Object; this.RegisterResource = function (ResName, ResValue) { if(ResName != undefined && ResName.toString().length) aryResIE[ResName] = ResValue; }; this.GetResourceByName = function(ResName) { if(ResName != undefined && ResName.toString().length) return (aryResIE[ResName] == undefined) ? "" : aryResIE[ResName]; else return ""; }; this.InitializeRes = function() { if(typeof _AniWeatherIEObj != 'undefined') { var _DefaultObj = new _AniWeather.IEDefaultRes; aryResIE = _DefaultObj.GetDefaultRes(); } }; } AniWeatherObj.Theme = function() { this.clrBorder=""; this.clrTitle=""; this.clrInput=""; this.clrBackground=""; this.urlMore=""; this.urlResize=""; } AniWeatherObj.LocSearchInfo = function() { this.locId = ""; this.name = ""; this.type = ""; } AniWeatherObj.BrowserAgent = function() { var BROWSER_NONE = 0; var BROWSER_IE = 1; var BROWSER_FF = 2; var BROWSER_CHROME = 3; var browserType; ; if(navigator.userAgent.indexOf("MSIE") >= 0) browserType = BROWSER_IE; else if(navigator.userAgent.toLowerCase().indexOf("gecko/") >= 0) browserType = BROWSER_FF; else if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) browserType = BROWSER_CHROME; else browserType = BROWSER_FF; var LEFTBUTTON = (browserType == BROWSER_IE) ? 1 : 0; var RIGHTBUTTON = (browserType == BROWSER_IE) ? 2 : 2; var MIDDLEBUTTON = (browserType == BROWSER_IE) ? 4 : 1; var aryLocalString; function getLocaleStringBundle() { if(browserType == BROWSER_FF) { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); return Bundle; } else return null; } function getLocaleString(strName) { if(browserType == BROWSER_FF) { try{ if(aryLocalString) return aryLocalString.GetStringFromName(strName); else return ""; } catch(err){ loghelper("Error in getting resource: " + strName); return ""; } } else if(browserType == BROWSER_IE) { return objCleekiIERes.GetResourceByName(strName); } else if(browserType == BROWSER_CHROME) { return objCleekiChromeRes.GetResourceByName(strName); } else { return ""; } } function getLocaleStringFormatted(strName, args) { if(browserType == BROWSER_FF) { if(aryLocalString) return aryLocalString.formatStringFromName(strName, args, args.length); else return ""; } else if(browserType == BROWSER_IE) { return objCleekiIERes.GetResourceByName(strName); } else { return getLocaleString(strName); } } aryLocalString = getLocaleStringBundle(); var aryGraphInfo = []; aryGraphInfo['national'] = new AniWeatherObj.GraphInfo('national', 'National', getLocaleString('graph.desc.national')); aryGraphInfo['vapor'] = new AniWeatherObj.GraphInfo('vapor', 'Vapor', getLocaleString('graph.desc.satellite')); aryGraphInfo['radar'] = new AniWeatherObj.GraphInfo('radar', 'Radar', getLocaleString('graph.desc.radar')); aryGraphInfo['uv'] = new AniWeatherObj.GraphInfo('uv', 'UV', getLocaleString('graph.desc.uv')); aryGraphInfo['pop'] = new AniWeatherObj.GraphInfo('pop', 'Pop', getLocaleString('graph.desc.precipitation')); aryGraphInfo['high'] = new AniWeatherObj.GraphInfo('high', 'High', getLocaleString('graph.desc.temperature')); aryGraphInfo['air'] = new AniWeatherObj.GraphInfo('air', 'Air', getLocaleString('graph.desc.air')); aryGraphInfo['alert'] = new AniWeatherObj.GraphInfo('alert', 'Alert', getLocaleString('graph.desc.alerts')); var aryTWCLinks = []; aryTWCLinks['Local Pollen Reports'] = 0; aryTWCLinks['Airport Conditions'] = 1; aryTWCLinks['Picnic Weather'] = 2; aryTWCLinks['Rush Hour Traffic'] = 3; aryTWCLinks['Lawn and Garden Weather'] = 4; var MIN_LAUNCHER_WIDTH = 480; var MIN_LAUNCHER_HEIGHT = 360; var GOOGLEICONBASE = "http://www.google.com"; //var WEEKDAYS = new Array(getLocaleString('weekdays.sun'),getLocaleString('weekdays.mon'),getLocaleString('weekdays.tue'),getLocaleString('weekdays.wed'),getLocaleString('weekdays.thu'),getLocaleString('weekdays.fri'),getLocaleString('weekdays.sat'),getLocaleString('weekdays.sun'),getLocaleString('weekdays.mon'),getLocaleString('weekdays.tue'),getLocaleString('weekdays.wed'),getLocaleString('weekdays.thu'),getLocaleString('weekdays.fri'),getLocaleString('weekdays.sat')); var WEEKDAYS = new Array(); WEEKDAYS[0] = getLocaleString('weekdays.sun'); WEEKDAYS[1] = getLocaleString('weekdays.mon'); WEEKDAYS[2] = getLocaleString('weekdays.tue'); WEEKDAYS[3] = getLocaleString('weekdays.wed'); WEEKDAYS[4] = getLocaleString('weekdays.thu'); WEEKDAYS[5] = getLocaleString('weekdays.fri'); WEEKDAYS[6] = getLocaleString('weekdays.sat'); WEEKDAYS[7] = getLocaleString('weekdays.sun'); WEEKDAYS[8] = getLocaleString('weekdays.mon'); WEEKDAYS[9] = getLocaleString('weekdays.tue'); WEEKDAYS[10] = getLocaleString('weekdays.wed'); WEEKDAYS[11] = getLocaleString('weekdays.thu'); WEEKDAYS[12] = getLocaleString('weekdays.fri'); WEEKDAYS[13] = getLocaleString('weekdays.sat'); var RAWWEEKDAYS = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); var FULLWEEKDAY = new Array(); FULLWEEKDAY['Now'] = getLocaleString('fullweekday.now'); FULLWEEKDAY['Today'] = getLocaleString('fullweekday.today'); FULLWEEKDAY['Sun'] = getLocaleString('fullweekday.sun'); FULLWEEKDAY['Mon'] = getLocaleString('fullweekday.mon'); FULLWEEKDAY['Tue'] = getLocaleString('fullweekday.tue'); FULLWEEKDAY['Wed'] = getLocaleString('fullweekday.wed'); FULLWEEKDAY['Thu'] = getLocaleString('fullweekday.thu'); FULLWEEKDAY['Fri'] = getLocaleString('fullweekday.fri'); FULLWEEKDAY['Sat'] = getLocaleString('fullweekday.sat'); var MONTHS = new Array("01","02","03","04","05","06","07","08","09","10","11","12"); var forecastWeatherFeed = 'http://xoap.weather.com/weather/local/[locid]?cc=*&dayf=5&link=xoap&prod=xoap&par=1106689085&key=3d761e6de925aa0d'; var currentWeatherFeed = 'http://xoap.weather.com/weather/local/[locid]?cc=*&link=xoap&prod=xoap&par=1106689085&key=3d761e6de925aa0d'; var settingPageName = "aniweather.config7.html"; var aniweatherHostName = "www.aniweather.com"; var feedbackPageName = "php/feedback.php"; var locSearchBase = 'http://xoap.weather.com/search/search?where='; var weatherSiteBase = 'http://www.aniweather.com/'; var weatherMediaBase = 'http://aniweather.s3.amazonaws.com/'; var iconBaseUrl = weatherMediaBase + 'media/weather/'; var tenDaysReportURL = "tenday.html"; var hourlyReportURL = "hourly.html"; var localeId = 'en-US'; var WEATHER_UPDATE_NONE = 0; var WEATHER_UPDATE_CURRENT = 1; var WEATHER_UPDATE_FORECAST = 2; var WEATHER_UPDATE_ALL = 3; var weatherUpdateMode = WEATHER_UPDATE_NONE; var eventDoc = null; var aryLocInfo = []; // var objAWIERes = new AniWeatherObj.IERes(); // var objAWChromeRes = new AniWeatherObj.ChromeRes(); var objConfigPara = new AniWeatherObj.ConfigPara(); var objWeatherInfo = new AniWeatherObj.WeatherInfo(); var objDefaultWeatherInfo = new AniWeatherObj.WeatherInfo(); var miniWidth = 240; var miniHeight = 256; var miniMargin = 32; var trayWidth = 100; var trayHeight = 120; var traySmallWidth = 84; var traySmallHeight = 96; var DEFAULT_WIDTH = 640; var DEFAULT_HEIGHT = []; DEFAULT_HEIGHT[0] = 436; DEFAULT_HEIGHT[1] = 420; var extendedWidth = DEFAULT_WIDTH; var extendedHeight = DEFAULT_HEIGHT[0]; var CANVAS_HEIGHT = 512; var extendedMargin = 32; var fadingColor = "#000000"; var fadingRatio = 80; var noticeSpan = 1; var displayMode = 0; var holderMargin = 8; var BUILDNO = 703; var mph2kmh = 1.609; var recheckDelay = 30000; var weatherCityLinkId = 'aniweathercity_'; var miniWeatherCanvasId = 'divMiniAniWeatherCanvas'; var miniWeatherId = 'divMiniAniWeather'; var miniHolderId = 'divMiniAniWeatherHolder'; var extendedWeatherCanvasId = 'divExtendedAniWeatherCanvas'; var extendedWeatherId = 'divExtendedAniWeather'; var extendedHolderId = 'divExtendedAniWeatherHolder'; var weatherDashboardId = 'weatherDashboard'; var weatherLauncherId = 'weatherLauncher'; var weatherLauncherHolderId = 'weatherLauncherHolder'; var xmlhttp = null; var xmlServer = null; var displayExtended = false; var timeLastCheck = 0; var forecastInterval = 3600000 * 4; //. 4 hr * 3600000 millisec/hr var currentInterval = 60000 * 30; //. 30 min * 60000 millisec/min var queryStatus = 0; var noticeWidth = 240; var noticeHeight =104; var noticeMoreHeight =216; var defaultGraphWidth = 362; var defaultGraphHeight = 280; var noticeTime = 5000; var graphTime = 8000; var launcherDist = noticeHeight/2; var launcherTime = 5; var launcherSpeed = launcherDist*2/launcherTime; var launcherAcce = 2*(launcherDist - launcherTime*launcherSpeed)/(launcherTime*launcherTime); var launcherIdx = 0; var tmLauncherAnimation = null; var curPort = null; var autoNoticeDelay = 5000; var checkIndex = 0; var tmLauncher = null; var tmSetPanelIcon = null; var docLauncher = null; var weatherHelperString = ""; var weatherDefaultString = ""; var lstReportId = {'current':0, 'today':1, '2nd':2, '3rd':3, '4th':4, '5th':5}; var currentReportId = ''; var currentGraphId = ''; String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } this.getCheckIndex = function() { return checkIndex; } this.setAniWeather = function() { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var gBrowser = wm.getMostRecentWindow("navigator:browser").gBrowser; gBrowser.selectedTab = gBrowser.addTab(this.getSettingPage()) ; } this.getSettingPage = function() { var aniweatherSettingURL = weatherSiteBase + 'locale/' + localeId +'/'+ settingPageName + '#settings'; return aniweatherSettingURL; } this.copyConfig = function(config) { objConfigPara.copyConfig(config); } function _attachLocIds(strWeather) { var num = Math.min(6, objConfigPara.locInfo.length); var strLocName = ""; var strLocId = ""; for(var i=0;i<num;i++) { var loc = objConfigPara.locInfo[i]; if(i > 0) { strLocName = strLocName + "|"; strLocId = strLocId + "|"; } strLocName = strLocName + loc.name; strLocId = strLocId + loc.id; } strWeather = strWeather + "&cities=" + strLocName + "&locids=" + strLocId; return strWeather; } this.attachLocIds = function(strWeather) { return _attachLocIds(strWeather); } function getObjectByEvent(event) { if(browserType == BROWSER_IE) { var objtype = typeof event.srcElement; if(objtype.toLowerCase() != "unknown") return event.srcElement; else return null; } else if(browserType == BROWSER_FF) return event.originalTarget; else if(browserType == BROWSER_CHROME) return event.srcElement; } function getDocumentByEvent(event) { if(browserType == BROWSER_FF) return event.originalTarget.ownerDocument; else return document; } function initPref() { var re = false; if(browserType == BROWSER_FF) { var chromeRegService = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService(); var xulChromeReg = chromeRegService.QueryInterface(Components.interfaces.nsIXULChromeRegistry); var toolkitChromeReg = chromeRegService.QueryInterface(Components.interfaces.nsIToolkitChromeRegistry); localeId = xulChromeReg.getSelectedLocale("aniweather"); objConfigPara.tempUnit = getIntPref('tempUnit'); objConfigPara.windUnit = getIntPref('windUnit'); objConfigPara.buildNo = getIntPref('buildNo'); objConfigPara.defaultLocId = getIntPref('defaultLocId'); var strId = getCharPref('locId'); // var strName = getCharPref('locName'); var strName = getComplexPref('locName'); var aryId = strId.split('|'); var aryName = strName.split('|'); objConfigPara.locInfo = []; var len = Math.min(aryId.length, aryName.length); for(var i=0;i<len;i++) { objConfigPara.locInfo.push({'name':aryName[i],'id':aryId[i]}); } objConfigPara.weatherWidth = getIntPref('weatherWidth'); objConfigPara.weatherHeight = getIntPref('weatherHeight'); objConfigPara.fadingRatio = getIntPref('fadingRatio'); objConfigPara.fadingColor = getCharPref('fadingColor'); objConfigPara.noticeSpan = getIntPref('noticeSpan'); objConfigPara.displayMode = getIntPref('displayMode'); objConfigPara.startNotice = getIntPref('startNotice'); objConfigPara.useMiniFrame = getIntPref('useMiniFrame'); objConfigPara.displayPosition = getCharPref('displayPosition'); objConfigPara.displayOffset = getIntPref('displayOffset'); objConfigPara.graphPreviewWidth = getIntPref('graphPreviewWidth'); objConfigPara.previewDelay = getIntPref('previewDelay'); var strLevels = getCharPref('displayLevel'); aryLevels = strLevels.split('|'); var aryOps = aryLevels[0].split(','); objConfigPara.displayLevel['current'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = aryLevels[1].split(','); objConfigPara.displayLevel['today'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = aryLevels[2].split(','); objConfigPara.displayLevel['2nd'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = aryLevels[3].split(','); objConfigPara.displayLevel['3rd'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = aryLevels[4].split(','); objConfigPara.displayLevel['4th'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); aryOps = aryLevels[5].split(','); objConfigPara.displayLevel['5th'] = new AniWeatherObj.DisplayLevel(aryOps[0], aryOps[1], aryOps[2], aryOps[3]); var strGraphic = getCharPref('graphicLevel'); aryGraphs = strGraphic.split('|'); this.graphLevel = []; var len = aryGraphs.length; var defOp = new Array(0,0); aryOps = len > 0 ? aryGraphs[0].split(',') : defOp; objConfigPara.graphLevel['national'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 1 ? aryGraphs[1].split(',') : defOp; objConfigPara.graphLevel['vapor'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 2 ? aryGraphs[2].split(',') : defOp; objConfigPara.graphLevel['radar'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 3 ? aryGraphs[3].split(',') : defOp; objConfigPara.graphLevel['uv'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 4 ? aryGraphs[4].split(',') : defOp; objConfigPara.graphLevel['pop'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 5 ? aryGraphs[5].split(',') : defOp; objConfigPara.graphLevel['high'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 6 ? aryGraphs[6].split(',') : defOp; objConfigPara.graphLevel['air'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); aryOps = len > 7 ? aryGraphs[7].split(',') : defOp; objConfigPara.graphLevel['alert'] = new AniWeatherObj.GraphLevel(aryOps[0], 360, 280, aryOps[1]); var firstRun = getIntPref("firstRun"); if(firstRun) { setIntPref("firstRun", 0); setTimeout(visitWelcomeTimer, 1000); } re = true; } else if(browserType == BROWSER_CHROME) { } return re; } function visitWelcomeTimer() { var aniweatherWelcomeURL = weatherSiteBase + 'locale/' + localeId +'/'+ settingPageName; gBrowser.selectedTab = gBrowser.addTab(aniweatherWelcomeURL) ; } function updateChromeStatus(status) { if(browserType == BROWSER_CHROME) { document.getElementById("AniWeatherStatus").innerHTML = status; } } function savePref() { var re = false; try{ if(browserType == BROWSER_FF) { setIntPref('tempUnit', objConfigPara.tempUnit); setIntPref('windUnit', objConfigPara.windUnit); setIntPref('buildNo', BUILDNO); setIntPref('defaultLocId', objConfigPara.defaultLocId); // setIntPref('locChanged', 1); var strId = ""; var strName = ""; var locNum = objConfigPara.locInfo.length; for(var i=0;i<locNum;i++) { strName = strName + objConfigPara.locInfo[i].name; strId = strId + objConfigPara.locInfo[i].id; if(i < locNum-1) { strName = strName + "|"; strId = strId + "|"; } } setCharPref('locId', strId); // setCharPref('locName', strName); setComplexPref('locName', strName); setIntPref('weatherWidth', objConfigPara.weatherWidth); setIntPref('weatherHeight', objConfigPara.weatherHeight); setIntPref('fadingRatio', objConfigPara.fadingRatio); setIntPref('noticeSpan', objConfigPara.noticeSpan); setIntPref('displayMode', objConfigPara.displayMode); setIntPref('startNotice', objConfigPara.startNotice); setIntPref('useMiniFrame', objConfigPara.useMiniFrame); setCharPref('fadingColor', objConfigPara.fadingColor); setCharPref('displayPosition', objConfigPara.displayPosition); setIntPref('displayOffset', objConfigPara.displayOffset); setIntPref('graphPreviewWidth', objConfigPara.graphPreviewWidth); setIntPref('previewDelay', objConfigPara.previewDelay); positionCanvas(); var strLevels = getLevelString(); setCharPref('displayLevel', strLevels); var strGraphs = getGraphString(); setCharPref('graphicLevel', strGraphs); re = true; } else if(browserType == BROWSER_CHROME) { var strSetting = _prepareChromeSettingString(); if(curPort) curPort.postMessage({'purpose':'save', 'data':strSetting}); } }catch(e){return false; } return re; } this.onPrefSaved = function(status) { if(status == 0) alert(getLocaleString('alert.applying.setting')); else alert(getLocaleString('alert.applying.setting.error')); } function getLevelString() { var level = objConfigPara.displayLevel['current']; var strLevels = level.show+','+level.showicon+','+level.showdesc+','+level.showtemp; level = objConfigPara.displayLevel['today']; strLevels = strLevels + '|'+ level.show+','+level.showicon+','+level.showdesc+','+level.showtemp; level = objConfigPara.displayLevel['2nd']; strLevels = strLevels + '|'+ level.show+','+level.showicon+','+level.showdesc+','+level.showtemp; level = objConfigPara.displayLevel['3rd']; strLevels = strLevels + '|'+ level.show+','+level.showicon+','+level.showdesc+','+level.showtemp; level = objConfigPara.displayLevel['4th']; strLevels = strLevels + '|'+ level.show+','+level.showicon+','+level.showdesc+','+level.showtemp; level = objConfigPara.displayLevel['5th']; strLevels = strLevels + '|'+ level.show+','+level.showicon+','+level.showdesc+','+level.showtemp; return strLevels; } function getGraphString() { try{ var level = objConfigPara.graphLevel['national']; var strLevels = level.show+','+level.animation; level = objConfigPara.graphLevel['vapor']; strLevels = strLevels + '|'+ level.show+','+level.animation; level = objConfigPara.graphLevel['radar']; strLevels = strLevels + '|'+ level.show+','+level.animation; level = objConfigPara.graphLevel['uv']; strLevels = strLevels + '|'+ level.show+','+level.animation; level = objConfigPara.graphLevel['pop']; strLevels = strLevels + '|'+ level.show+','+level.animation; level = objConfigPara.graphLevel['high']; strLevels = strLevels + '|'+ level.show+','+level.animation; level = objConfigPara.graphLevel['air']; strLevels = strLevels + '|'+ level.show+','+level.animation; level = objConfigPara.graphLevel['alert']; strLevels = strLevels + '|'+ level.show+','+level.animation; }catch(e){alert(e.toString());} return strLevels; } function _prepareChromeSettingString() { var strSetting = objConfigPara.tempUnit; strSetting = strSetting +"&"+ BUILDNO; strSetting = strSetting +"&"+ objConfigPara.defaultLocId; var strId = ""; var strName = ""; var locNum = objConfigPara.locInfo.length; for(var i=0;i<locNum;i++) { strName = strName + objConfigPara.locInfo[i].name; strId = strId + objConfigPara.locInfo[i].id; if(i < locNum-1) { strName = strName + "|"; strId = strId + "|"; } } strSetting = strSetting +"&"+ strName; strSetting = strSetting +"&"+ strId; strSetting = strSetting +"&"+ objConfigPara.windUnit; strSetting = strSetting +"&"+ objConfigPara.weatherWidth; strSetting = strSetting +"&"+ objConfigPara.weatherHeight; var strLevels = getLevelString(); strSetting = strSetting +"&"+ strLevels; strSetting = strSetting +"&"+ objConfigPara.fadingRatio; strSetting = strSetting +"&"+ objConfigPara.fadingColor; strSetting = strSetting +"&"+ objConfigPara.noticeSpan; strSetting = strSetting +"&"+ objConfigPara.displayMode; strSetting = strSetting +"&"+ objConfigPara.startNotice; var strGraphs = getGraphString(); strSetting = strSetting +"&"+ strGraphs; strSetting = strSetting +"&"+ objConfigPara.useMiniFrame; strSetting = strSetting +"&"+ objConfigPara.graphPreviewWidth; strSetting = strSetting +"&"+ objConfigPara.previewDelay; return strSetting; } this.prepareChromeSettingString = function() { return _prepareChromeSettingString(); } function setEventListener(obj, evt, func, bubble) { try { if(browserType == BROWSER_IE) { obj.detachEvent('on'+evt, func); obj.attachEvent('on'+evt, func, bubble); } else /// if(browserType == BROWSER_FF) obj.addEventListener(evt, func, bubble); } catch(err) { // loghelper('Error in setEventListener: ' + err + '. Function: ' + func.name, 2); } } function loghelper(msg) { if(browserType == BROWSER_FF) { var consoleService = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); consoleService.logStringMessage('*AniWeather* --- ' + msg); } } this.registerPort = function(port) { curPort = port; } function positionCanvas() { //. nav-bar, main-menubar, status-bar, toolbar-menubar, "PersonalToolbar" try{ var holderId = getCharPref('displayPosition'); var offset = getIntPref('displayOffset'); var holder = document.getElementById(holderId); if (!holder) holder = document.getElementById("status-bar"); if(!holder) return; var canvas = document.getElementById("aniweather_canvas"); //. Remove it first if it already exists var children = holder.childNodes; var pos = -1; for (var idx=0; idx<children.length; idx++) { if (children[idx] == canvas) pos = idx; } canvas.parentNode.removeChild(canvas); var newcanvas = null; if (holder.localName == "statusbar") { if (canvas.localName != "statusbarpanel") newcanvas = document.createElement("statusbarpanel"); } else { if (canvas.localName == "statusbarpanel") newcanvas = document.createElement("hbox"); } if (newcanvas) { newcanvas.setAttribute("id", "aniweather_canvas"); while (canvas.hasChildNodes()) newcanvas.appendChild(canvas.firstChild); } else //. Anything wrong here? newcanvas = canvas; children = holder.childNodes; pos = offset; if ((children.length == 0) || (pos >= children.length) || (pos < 0)) holder.appendChild(newcanvas); else holder.insertBefore(newcanvas, children[pos]); }catch(e){alert('Error in positioning AniWeather:'+e.toString());} } function smartKeyPress(event) { try{ var event = (!event)? window.event : event; var keycode ; if(typeof event.keyCode != "undefined") // IE keycode = event.keyCode; else keycode = event.which; if(keycode == 27) // ESC { if(removeWeather(true, true) == 0) { var doc = getCurDocument(); aryFlash = doc.getElementsByTagName('object'); var len = aryFlash.length; for(var i=0;i<len;i++) { var objFlash = aryFlash[i]; objFlash.style.visibility = "visible"; } aryFlash = doc.getElementsByTagName('embed'); var len = aryFlash.length; for(var i=0;i<len;i++) { var objFlash = aryFlash[i]; objFlash.style.visibility = "visible"; } } } }catch(e){alert(e.toString());} } this.MainStart = function(getWeather, getHook) { var re = initPref(); if(browserType == BROWSER_FF) { this.getServerStatus(); window.addEventListener("load", positionCanvas, false); var appcontent = document.getElementById("appcontent"); // browser if(appcontent) { setEventListener(appcontent, "DOMContentLoaded", onPageLoad, false); } // this.getWeatherDetails(true, false, null); _checkWeatherTimer(objConfigPara.startNotice == 1); } else if(browserType == BROWSER_IE) { onPageLoad(); } else if(browserType == BROWSER_CHROME) { // setEventListener(document, 'keydown', smartKeyPress, false); if(getHook) onPageLoad(); if(getWeather) this.getWeatherDetails(true, false, null); } }; function goToURL(url, show) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interfaces.nsIWindowMediator); var mainWindow = wm.getMostRecentWindow("navigator:browser"); browser = mainWindow.getBrowser(); browser.selectedTab = browser.addTab(url); } function onAddLoc(event) { eventDoc = getDocumentByEvent(event); var name = eventDoc.getElementById('inputLocation').value; eventDoc.getElementById('loadSearching').style.display = "block"; eventDoc.getElementById('divSelect').style.display = "none"; if(browserType == BROWSER_FF) { launchLocSearch(name); } else if(browserType == BROWSER_CHROME) { if(curPort) { curPort.postMessage({'purpose':'locid', 'name':name}); } } } this.searchLocalId = function(name) { launchLocSearch(name); } function serverStatusCallback() { if (xmlServer && xmlServer.readyState==4) { var status = -1; if(xmlServer.status==200) { var data = xmlServer.responseText; var aryValues = data.split(','); if(aryValues.length == 2 && aryValues[0] == '0') status = 0; } if(status == 0 ) { aniweatherHostName = "www.aniweather.com"; weatherSiteBase = 'http://www.aniweather.com/'; } else { aniweatherHostName = "aniweather.s3.amazonaws.com"; weatherSiteBase = 'http://aniweather.s3.amazonaws.com/www/'; } } } this.getServerType = function() { if(aniweatherHostName == "www.aniweather.com") return 0; else return 1; } this.setServerType = function(type) { if(type == 0) { aniweatherHostName = "www.aniweather.com"; weatherSiteBase = 'http://www.aniweather.com/'; } else { aniweatherHostName = "aniweather.s3.amazonaws.com"; weatherSiteBase = 'http://aniweather.s3.amazonaws.com/www/'; } } this.getServerStatus = function() { xmlServer=null; var url = "http://www.aniweather.com/status.html"; if (window.XMLHttpRequest) { // code for all new browsers xmlServer=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE5 and IE6 xmlServer=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlServer!=null) { xmlServer.onreadystatechange= serverStatusCallback; xmlServer.open("GET",url,true); xmlServer.send(null); } } function launchLocSearch(name) { xmlhttp=null; // var url = 'http://www.google.com/ig/api?weather='+objConfigPara.locationInfo.city; var url = locSearchBase+""+name; if (window.XMLHttpRequest) { // code for all new browsers xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE5 and IE6 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlhttp!=null) { xmlhttp.onreadystatechange=LocInfoReady; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else { // alert("Error in loading the loc info."); } } function LocInfoReady() { if (xmlhttp && xmlhttp.readyState==4) { // 4 = "loaded" if (xmlhttp.status==200) { // 200 = OK // ...our code here... parseLocInfo(xmlhttp.responseText); } else { // alert("Error in loading the weather info."); } } } this.localIdReady = function(data) { var aryIds = []; if(data.length > 0) aryIds = data.split('|'); var len = aryIds.length; aryLocInfo = []; for(var i=0;i<len;i++) { var aryVal = aryIds[i].split('&'); var objLoc = new AniWeatherObj.LocSearchInfo(); objLoc.name = aryVal[0]; objLoc.id = aryVal[1]; aryLocInfo.push(objLoc); } updateLocList(); } function parseLocInfo(data) { aryLocInfo = []; var strLocId = ""; try{ if(data.length) { var xmlDoc = parseXML(data); //. Head info var objElem = xmlDoc.getElementsByTagName("search")[0]; var aryNodes = objElem.childNodes; var len = aryNodes.length; // <loc id="USNY0996" type="1">New York, NY</loc> for(var i=0;i<len;i++) { var objData = aryNodes[i]; if(objData.nodeName.toLowerCase() == "loc") { var objLoc = new AniWeatherObj.LocSearchInfo(); objLoc.name = objData.childNodes[0].nodeValue; objLoc.id = objData.attributes.getNamedItem("id").value; objLoc.type = objData.attributes.getNamedItem("id").value; aryLocInfo.push(objLoc); if(strLocId.length > 0) strLocId = strLocId + "|"; strLocId = strLocId + objLoc.name +"&" +objLoc.id ; } } } }catch(e){ // alert(e.toString()); var strLocId = ""; var posStart; var posEnd; var startToken = 'id="'; var tokenLen = startToken.length; var strId = ""; var strName = ""; var idx = 0; while(true) { // <loc id="USNY0996" type="1">New York, NY</loc> posStart = data.indexOf(startToken); if(posStart) { data = data.substr(posStart+tokenLen); posEnd = data.indexOf('"'); if(posEnd > 0) { strId = data.substr(0, posEnd); data = data.substr(posEnd); } else //. Broken? break; posStart = data.indexOf('>'); posEnd = data.indexOf('<'); if(posStart > 0 && posEnd > 0) { strName = data.substr(posStart+1, posEnd-posStart-1); data = data.substr(posEnd); } else //. Broken? break; if(idx > 0) strLocId = strLocId + "|"; strLocId = strLocId + strName +"&" +strId; idx++; } else break; } } if(browserType == BROWSER_FF) { updateLocList(); } else if(browserType == BROWSER_CHROME) { var objLocId = document.getElementById('hiddenLocId'); if(objLocId) objLocId.value = strLocId; var objReady = document.getElementById('chkLocIdReady'); if(objReady) { objReady.checked = true; objReady.onclick(); } } } function updateLocList() { try { var divLoc = eventDoc.getElementById('divLocations'); divLoc.innerHTML = ""; // var ulLoc = eventDoc.getElementById('ulAniweatherLocList'); // if(ulLoc) // divLoc.removeChild(ulLoc); // ulLoc = document.createElement("ul"); // ulLoc.id = 'ulAniweatherLocList'; eventDoc.getElementById('loadSearching').style.display = "none"; if(aryLocInfo.length > 0) { var strContent = "<ul id='ulAniweatherLocList'>"; var len = aryLocInfo.length; for(var i=0;i<len;i++) { var objLoc = aryLocInfo[i]; strContent = strContent + '<li><a onclick="chooseLocation(event);" id="'+objLoc.id+'" href="javascript:; ">'+objLoc.name+'</a></li>'; } strContent = strContent + "</ul>"; // ulLoc.innerHTML = strContent; // divLoc.appendChild(ulLoc); divLoc.innerHTML = strContent; eventDoc.getElementById('divSelect').style.display = "block"; } else { alert(getLocaleString('alert.no.locations.found')); } }catch(err){} } function _initOptionSettings(doc) { try{ doc.getElementById('rdoF').checked = (objConfigPara.tempUnit == 0); doc.getElementById('rdoC').checked = (objConfigPara.tempUnit == 1); doc.getElementById('rdoM').checked = (objConfigPara.windUnit == 0); doc.getElementById('rdoK').checked = (objConfigPara.windUnit == 1); doc.getElementById('divSelect').style.display = "none"; doc.getElementById('loadSearching').style.display = "none"; doc.getElementById('defaultLocId').value = objConfigPara.defaultLocId; doc.getElementById('defaultLoc').innerHTML = objConfigPara.locInfo[objConfigPara.defaultLocId].name; var objLocList = doc.getElementById('lstLocations'); var len = objConfigPara.locInfo.length; for (var i=0;i<len;i++) { objLocList.add(new Option(objConfigPara.locInfo[i].name, objConfigPara.locInfo[i].id), null); } doc.getElementById('lstAnimationSize').value = objConfigPara.weatherWidth; doc.getElementById('lstFadingRatio').value = objConfigPara.fadingRatio; doc.getElementById('lstFadingColor').value = objConfigPara.fadingColor; doc.getElementById('lstNoticeSpan').value = objConfigPara.noticeSpan; doc.getElementById('lstDisplayMode').value = objConfigPara.displayMode; doc.getElementById('chkStartNotice').checked = (objConfigPara.startNotice == 1) ? true:false; doc.getElementById('lstDisplayPosition').value = objConfigPara.displayPosition; doc.getElementById('inputDisplayOffset').value = objConfigPara.displayOffset; doc.getElementById('lstGraphicPreviewSize').value = objConfigPara.graphPreviewWidth; doc.getElementById('lstPreviewDelay').value = objConfigPara.previewDelay; var obj = doc.getElementById('chkUseMiniFrame'); if(obj) obj.checked = (objConfigPara.useMiniFrame == 1) ? true:false; var level = objConfigPara.displayLevel['current']; doc.getElementById('chkCurrent').checked = (level.show == 1) ? true : false; doc.getElementById('chkCurrentIcon').checked = (level.showicon == 1) ? true : false; doc.getElementById('chkCurrentDesc').checked = (level.showdesc == 1) ? true : false; doc.getElementById('chkCurrentTemp').checked = (level.showtemp == 1) ? true : false; level = objConfigPara.displayLevel['today']; doc.getElementById('chkToday').checked = (level.show == 1) ? true : false; doc.getElementById('chkTodayIcon').checked = (level.showicon == 1) ? true : false; doc.getElementById('chkTodayDesc').checked = (level.showdesc == 1) ? true : false; doc.getElementById('chkTodayTemp').checked = (level.showtemp == 1) ? true : false; level = objConfigPara.displayLevel['2nd']; doc.getElementById('chk2nd').checked = (level.show == 1) ? true : false; doc.getElementById('chk2ndIcon').checked = (level.showicon == 1) ? true : false; doc.getElementById('chk2ndDesc').checked = (level.showdesc == 1) ? true : false; doc.getElementById('chk2ndTemp').checked = (level.showtemp == 1) ? true : false; level = objConfigPara.displayLevel['3rd']; doc.getElementById('chk3rd').checked = (level.show == 1) ? true : false; doc.getElementById('chk3rdIcon').checked = (level.showicon == 1) ? true : false; doc.getElementById('chk3rdDesc').checked = (level.showdesc == 1) ? true : false; doc.getElementById('chk3rdTemp').checked = (level.showtemp == 1) ? true : false; level = objConfigPara.displayLevel['4th']; doc.getElementById('chk4th').checked = (level.show == 1) ? true : false; doc.getElementById('chk4thIcon').checked = (level.showicon == 1) ? true : false; doc.getElementById('chk4thDesc').checked = (level.showdesc == 1) ? true : false; doc.getElementById('chk4thTemp').checked = (level.showtemp == 1) ? true : false; level = objConfigPara.displayLevel['5th']; doc.getElementById('chk5th').checked = (level.show == 1) ? true : false; doc.getElementById('chk5thIcon').checked = (level.showicon == 1) ? true : false; doc.getElementById('chk5thDesc').checked = (level.showdesc == 1) ? true : false; doc.getElementById('chk5thTemp').checked = (level.showtemp == 1) ? true : false; var graph = objConfigPara.graphLevel['national']; doc.getElementById('chkNational').checked = (graph.show == 1) ? true : false; doc.getElementById('chkNationalAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['vapor']; doc.getElementById('chkVapor').checked = (graph.show == 1) ? true : false; doc.getElementById('chkVaporAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['radar']; doc.getElementById('chkRadar').checked = (graph.show == 1) ? true : false; doc.getElementById('chkRadarAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['uv']; doc.getElementById('chkUV').checked = (graph.show == 1) ? true : false; doc.getElementById('chkUVAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['pop']; doc.getElementById('chkPop').checked = (graph.show == 1) ? true : false; doc.getElementById('chkPopAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['high']; doc.getElementById('chkHigh').checked = (graph.show == 1) ? true : false; doc.getElementById('chkHighAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['air']; doc.getElementById('chkAir').checked = (graph.show == 1) ? true : false; doc.getElementById('chkAirAnimation').checked = (graph.animation == 1) ? true : false; graph = objConfigPara.graphLevel['alert']; doc.getElementById('chkAlert').checked = (graph.show == 1) ? true : false; doc.getElementById('chkAlertAnimation').checked = (graph.animation == 1) ? true : false; var btnAdd = doc.getElementById('btnAddNew'); setEventListener(btnAdd, 'click', onAddLoc, false); var frmAddLoc = doc.getElementById('frmAddLoc'); setEventListener(frmAddLoc, 'submit', onAddLoc, false); var btnOK = doc.getElementById('btnOK'); setEventListener(btnOK, 'click', onApplySetting, false); }catch(e){} } function validateSetting(doc) { var objLocList = doc.getElementById('lstLocations'); if(objLocList.options.length == 0) { alert(getLocaleString('alert.need.one.location')); return false; } if(!doc.getElementById('chkCurrent').checked && !doc.getElementById('chkToday').checked && !doc.getElementById('chk2nd').checked && !doc.getElementById('chk3rd').checked && !doc.getElementById('chk4th').checked && !doc.getElementById('chk5th').checked) { alert(getLocaleString('alert.need.one.condition')); return false; } } function getStatusDisplay(doc, day) { var objLevel = new AniWeatherObj.DisplayLevel( doc.getElementById('chk'+day).checked ? 1:0, doc.getElementById('chk'+day+'Icon').checked ? 1:0, doc.getElementById('chk'+day+'Desc').checked ? 1:0, doc.getElementById('chk'+day+'Temp').checked ? 1:0); return objLevel; } function getGraphDisplay(doc, name) { var objGraph = new AniWeatherObj.GraphLevel( doc.getElementById('chk'+name).checked ? 1:0, defaultGraphWidth, defaultGraphHeight, doc.getElementById('chk'+name+'Animation').checked ? 1:0); return objGraph; } function onApplySetting(event) { event = event ? event : window.event; var doc = getDocumentByEvent(event); if(validateSetting(doc) == false) return false; try{ var objTempConfig = new AniWeatherObj.ConfigPara(); objTempConfig.tempUnit = doc.getElementById('rdoC').checked ? 1 : 0; objTempConfig.windUnit = doc.getElementById('rdoK').checked ? 1 : 0; objTempConfig.defaultLocId = parseInt(doc.getElementById('defaultLocId').value); objTempConfig.locInfo = []; var objLocList = doc.getElementById('lstLocations'); var len = objLocList.options.length; var addedNum = 0; for(var i=0;i<len;i++) { objTempConfig.locInfo.push({'name':objLocList.options[i].text, 'id':objLocList.options[i].value}); addedNum++; } objTempConfig.weatherWidth = parseInt(doc.getElementById('lstAnimationSize').value); objTempConfig.fadingRatio = parseInt(doc.getElementById('lstFadingRatio').value); objTempConfig.fadingColor = doc.getElementById('lstFadingColor').value; objTempConfig.noticeSpan = parseInt(doc.getElementById('lstNoticeSpan').value); objTempConfig.displayMode = parseInt(doc.getElementById('lstDisplayMode').value); objTempConfig.displayPosition = doc.getElementById('lstDisplayPosition').value; objTempConfig.startNotice = doc.getElementById('chkStartNotice').checked ? 1 : 0; objTempConfig.graphPreviewWidth = parseInt(doc.getElementById('lstGraphicPreviewSize').value); objTempConfig.previewDelay = parseInt(doc.getElementById('lstPreviewDelay').value); var value = parseInt(doc.getElementById('inputDisplayOffset').value); objTempConfig.displayOffset = isNaN(value) ? -1 : value; var obj = doc.getElementById('chkUseMiniFrame'); if(obj) objTempConfig.useMiniFrame = obj.checked ? 1:0; objTempConfig.displayLevel['current'] = getStatusDisplay(doc, "Current"); objTempConfig.displayLevel['today'] = getStatusDisplay(doc, "Today"); objTempConfig.displayLevel['2nd'] = getStatusDisplay(doc, "2nd"); objTempConfig.displayLevel['3rd'] = getStatusDisplay(doc, "3rd"); objTempConfig.displayLevel['4th'] = getStatusDisplay(doc, "4th"); objTempConfig.displayLevel['5th'] = getStatusDisplay(doc, "5th"); objTempConfig.graphLevel['national'] = getGraphDisplay(doc, "National"); objTempConfig.graphLevel['vapor'] = getGraphDisplay(doc, "Vapor"); objTempConfig.graphLevel['radar'] = getGraphDisplay(doc, "Radar"); objTempConfig.graphLevel['uv'] = getGraphDisplay(doc, "UV"); objTempConfig.graphLevel['pop'] = getGraphDisplay(doc, "Pop"); objTempConfig.graphLevel['high'] = getGraphDisplay(doc, "High"); objTempConfig.graphLevel['air'] = getGraphDisplay(doc, "Air"); objTempConfig.graphLevel['alert'] = getGraphDisplay(doc, "Alert"); // Validate again if(objTempConfig.defaultLocId < 0 || objTempConfig.defaultLocId >= objTempConfig.locInfo.length) objTempConfig.defaultLocId = 0; objConfigPara.copyConfig(objTempConfig); if(savePref()) { if(browserType == BROWSER_FF) _getWeatherDetails(false, false, null); alert(getLocaleString('alert.applying.setting')); } }catch(e){} } function onPageLoad(event) { try{ // alert(location); var myLocalStorage = localStorage; }catch(e){} try{ if(browserType == BROWSER_FF) { eventDoc = getObjectByEvent(event); // doc is document that triggered "onload" event } else eventDoc = document; var hostName = eventDoc.defaultView.location.hostname.toLowerCase(); var strURL = eventDoc.URL.toLowerCase(); var pos = strURL.indexOf(settingPageName); if(pos > 0 && aniweatherHostName == hostName) //. TODO: refine the checking { if(browserType == BROWSER_CHROME) { //. Working around Chrome's racing bug. setTimeout(function(){ if(curPort) curPort.postMessage({'purpose':'getsetting'}); }, 300); } else _initOptionSettings(eventDoc); } }catch(e){} } this.onGetChromeSetting = function(value) { objConfigPara.parseChromeSetting(value); _initOptionSettings(eventDoc); } function getIntPref(name) { if(browserType == BROWSER_FF) { // prefManager = Components.classes["@mozilla.org/preferences-service;1"] // .getService(Components.interfaces.nsIPrefService).getBranch("extensions.aniweather."); // var nValue = prefManager.getIntPref(name); // return nValue; var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); return prefManager.getIntPref('extensions.aniweather.'+name); } else if(browserType == BROWSER_CHROME) { } else return -1; } function setIntPref(name, value) { if(browserType == BROWSER_FF) { /* /// The following masked codes would trigger compatibility issue w/ Google Reader Watcher. /// Not sure why, but the modify codes are OK. prefManager = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService).getBranch("extensions.aniweather."); var nValue = prefManager.setIntPref(name, value); return nValue; */ var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); prefManager.setIntPref('extensions.aniweather.'+name, value); } } function checkPrefPresent(name) { if(browserType == BROWSER_FF) { // prefManager = Components.classes["@mozilla.org/preferences-service;1"] // .getService(Components.interfaces.nsIPrefService).getBranch("extensions.aniweather."); // var strValue = prefManager.getCharPref(name); // return strValue; var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); return prefManager.prefHasUserValue('extensions.aniweather.'+name); } else return false; } function getCharPref(name) { if(browserType == BROWSER_FF) { // prefManager = Components.classes["@mozilla.org/preferences-service;1"] // .getService(Components.interfaces.nsIPrefService).getBranch("extensions.aniweather."); // var strValue = prefManager.getCharPref(name); // return strValue; var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); return prefManager.getCharPref('extensions.aniweather.'+name); } else return ""; } function setCharPref(name, value) { if(browserType == BROWSER_FF) { // prefManager = Components.classes["@mozilla.org/preferences-service;1"] // .getService(Components.interfaces.nsIPrefService).getBranch("extensions.aniweather."); // var strValue = prefManager.setCharPref(name, value); // return strValue; var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); prefManager.setCharPref('extensions.aniweather.'+name, value); } } function getComplexPref(name) { if(browserType == BROWSER_FF) { var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); return prefManager.getComplexValue('extensions.aniweather.'+name, Components.interfaces.nsISupportsString).data; } else return ""; } function setComplexPref(name, value) { if(browserType == BROWSER_FF) { var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); var str = Components.classes["@mozilla.org/supports-string;1"] .createInstance(Components.interfaces.nsISupportsString); str.data = value; prefManager.setComplexValue('extensions.aniweather.'+name, Components.interfaces.nsISupportsString, str); } } this.menuSearch = function(event) { obj = getObjectByEvent(event); var locId = obj.value; this.getWeatherDetails(false, true, null, locId) } this.tenDaysReport = function(event) { var obj = getObjectByEvent(event); var locId = obj.value; var len = objConfigPara.locInfo.length; for(i=0;i<len;i++) { var objLoc = objConfigPara.locInfo[i]; if(objLoc.id == locId) { var name = objLoc.name; var url = weatherSiteBase + tenDaysReportURL + "?id=" + locId + "&name=" + name + "&phase=" + objWeatherInfo.currentInfo.moonicon; goToURL(url, true); break; } } } this.hourlyReport = function(event) { var obj = getObjectByEvent(event); var locId = obj.value; var len = objConfigPara.locInfo.length; for(i=0;i<len;i++) { var objLoc = objConfigPara.locInfo[i]; if(objLoc.id == locId) { var name = objLoc.name; var url = weatherSiteBase + hourlyReportURL + "?id=" + locId + "&name=" + name + "&phase=" + objWeatherInfo.currentInfo.moonicon; goToURL(url, true); break; } } } this.updateLocationPopup = function(event) { var popup = getObjectByEvent(event); // var popup = document.getElementById("aniweather-status-location-popup"); // aniweather-status-location-popup // aniweather-status-hourly-popup // aniweather-status-10day-popup if(!popup) return; //. Clear current set while (popup.firstChild) { popup.removeChild(popup.firstChild); } var len = objConfigPara.locInfo.length; for(i=0;i<len;i++) { var objLoc = objConfigPara.locInfo[i]; var objItem = document.createElement("menuitem"); objItem.setAttribute("label", objLoc.name); objItem.setAttribute("value", objLoc.id); objItem.setAttribute("id", objLoc.id); if(i==objConfigPara.defaultLocId) { objItem.setAttribute("type", "checkbox"); objItem.setAttribute("checked", "true"); } // objItem.setAttribute("class", "menuitem-iconic"); // objItem.setAttribute("image", aryChannels[i].logoimg); if(popup.id == "aniweather-status-location-popup") objItem.setAttribute("oncommand", "AniWeatherObj.menuSearch(event);"); else if(popup.id == "aniweather-status-10day-popup") objItem.setAttribute("oncommand", "AniWeatherObj.tenDaysReport(event);"); else if (popup.id == "aniweather-status-hourly-popup") objItem.setAttribute("oncommand", "AniWeatherObj.hourlyReport(event);"); popup.appendChild(objItem); } } function getDateInfo(strDate) { //. // String format: 5/30/09 1:22 PM Local Time var objDate=new Date(); var yearPrefix = Math.floor(objDate.getFullYear()/100); aryDates = strDate.split('/'); var month = parseInt(aryDates[0].trim()) - 1; var monthdate = parseInt(aryDates[1].trim()); var strYear = aryDates[2].trim(); var pos = strYear.indexOf(' '); if(pos) strYear = strYear.substr(0, pos); if(strYear.length == 2) strYear = yearPrefix +""+ strYear ; var year = parseInt(strYear); objDate.setFullYear(year, month, monthdate); //. Set to the noon of that day objDate.setTime(objDate.getTime()); //. WEEKDAYS month = objDate.getMonth(); var strDate = objDate.getDate(); if(strDate < 10) strDate = "0"+strDate; monthdate = MONTHS[objDate.getMonth()]+'/'+strDate; var day = objDate.getDay(); var curtime = objDate.getTime(); objWeatherInfo.day = WEEKDAYS[day]; objWeatherInfo.days = objWeatherInfo.day+","+WEEKDAYS[day+1]+","+WEEKDAYS[day+2]+","+WEEKDAYS[day+3]+","+WEEKDAYS[day+4]; objWeatherInfo.dates = monthdate; var oneday = 24*3600000; // 1day = 24hr * 3600 sec/hr * 1000millisec/sec for(var i=0;i<4;i++) { curtime += oneday; objDate.setTime(curtime); var strDate = objDate.getDate(); if(strDate < 10) strDate = "0"+strDate; objWeatherInfo.dates = objWeatherInfo.dates +","+MONTHS[objDate.getMonth()]+'/'+strDate; objWeatherInfo.dailyInfo[i+1].weekday = RAWWEEKDAYS[day+i+1]; } objWeatherInfo.dailyInfo[0].weekday = RAWWEEKDAYS[day]; } this.getWeatherDetails = function(force, display, event, locId) { _getWeatherDetails(force, display, event, locId); } function checkStoredWeatherData(locId, type) { var type = (typeof type == 'undefined') ? 0 : type; var checkId = ''; if(type == 0) checkId = locId +'.current'; else checkId = locId +'.forcast'; var status={'code':0,'time':0,'data':''}; if(browserType == BROWSER_FF) { var found = checkPrefPresent(checkId); if(!found) { setCharPref(checkId, ''); status.code = 1; } else { var data = getCharPref(checkId); var aryData = data.split('|'); if(aryData.length < 2) status.code = 2; else { status.time = aryData[0]; status.data = aryData[1]; } } } else if(browserType == BROWSER_CHROME) { var data = localStorage.getItem(checkId); if(data != null && data.length > 0) { var aryData = data.split('|'); if(aryData.length < 2) status.code = 2; else { status.time = aryData[0]; status.data = aryData[1]; } } else status.code = 1; updateStatus(locId+','+type+','+status.code); } return status; } function _getWeatherDetails(force, display, event, locId) { if(queryStatus == 1) return; if(event && event.button == RIGHTBUTTON) return; locId = locId ? locId : objConfigPara.locInfo[objConfigPara.defaultLocId].id; var now = new Date(); var nowms = now.getTime(); var isDefault = (locId == objConfigPara.locInfo[objConfigPara.defaultLocId].id); var forcastWeatherData = ""; var currentWeatherData = ""; var weatherFeedURL = ''; var currentStatus = checkStoredWeatherData(locId, 0); var forecastStatus = checkStoredWeatherData(locId, 1); weatherUpdateMode = WEATHER_UPDATE_NONE; if(forecastStatus.code != 0 || (nowms - forecastStatus.time) > forecastInterval) { //. Update all weatherUpdateMode = WEATHER_UPDATE_ALL; weatherFeedURL = forecastWeatherFeed; } else { forcastWeatherData = forecastStatus.data; if(nowms - forecastStatus.time < currentInterval) currentWeatherData = forecastStatus.data; else if(currentStatus.code != 0 || (nowms - currentStatus.time) > currentInterval) { //. Only update current weatherUpdateMode = WEATHER_UPDATE_CURRENT; weatherFeedURL = currentWeatherFeed; } else currentWeatherData = currentStatus.data; } extendedWidth = objConfigPara.weatherWidth; displayMode = objConfigPara.displayMode; extendedHeight = DEFAULT_HEIGHT[displayMode]*extendedWidth/DEFAULT_WIDTH; fadingRatio = objConfigPara.fadingRatio; fadingColor = objConfigPara.fadingColor; noticeSpan = objConfigPara.noticeSpan; displayExtended = display; //. loghelper('Update mode ' +weatherUpdateMode+ ' for '+ locId); if((weatherUpdateMode & WEATHER_UPDATE_FORECAST) == 0) { parseWeatherInfo(forcastWeatherData, WEATHER_UPDATE_FORECAST, false, false); } if((weatherUpdateMode & WEATHER_UPDATE_CURRENT) == 0) { parseWeatherInfo(currentWeatherData, WEATHER_UPDATE_CURRENT, false, weatherUpdateMode == WEATHER_UPDATE_NONE); } if(weatherUpdateMode == WEATHER_UPDATE_NONE) { queryStatus = 2; if(displayExtended) { _displayExtendedWeather(); } return; } if(weatherUpdateMode != WEATHER_UPDATE_NONE || force || event.button == LEFTBUTTON) { queryStatus = 1; xmlhttp=null; // var url = 'http://www.google.com/ig/api?weather='+objConfigPara.locationInfo.city; var url = weatherFeedURL.replace('[locid]', locId); if (window.XMLHttpRequest) { // code for all new browsers xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE5 and IE6 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlhttp!=null) { xmlhttp.onreadystatechange=AniWeatherInfoReady; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else { // alert("Error in loading the weather info."); } } } function AniWeatherInfoReady() { if (xmlhttp && xmlhttp.readyState==4) { // 4 = "loaded" if (xmlhttp.status==200) { // 200 = OK // ...our code here... parseWeatherInfo(xmlhttp.responseText, weatherUpdateMode, true, true); } else { // Sth. wrong in getting the weather info. Try again later. queryStatus = 0; setTimeout(function(){ _getWeatherDetails(false, false, null); }, recheckDelay); } } } function manualParserGet(data, start, end) { var objRe = null; var posFrom=data.indexOf(start); var posTo = data.indexOf(end); if(posFrom >= 0 && posTo > 0) { posFrom = posFrom+start.length; objRe = {'value':data.substr(posFrom, posTo - posFrom), 'newpos':posTo+end.length}; } return objRe; } function parseWeatherInfo(data, mode, updateStorage, notify) { var updateStorage = (typeof updateStorage == "undefined") ? false : updateStorage; var bProcessed = true; try{ if(data.length) { var xmlDoc = parseXML(data); //. Head info var objElem = xmlDoc.getElementsByTagName("head")[0]; var aryNodes = objElem.childNodes; var len = aryNodes.length; // locale, form, ut, ud, us, up, ur for(var i=0;i<len;i++) { var objData = aryNodes[i]; if(objData.nodeName.toLowerCase() == "locale") objWeatherInfo.envInfo.locale = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "form") objWeatherInfo.envInfo.form = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "ut") objWeatherInfo.envInfo.ut = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "ud") objWeatherInfo.envInfo.ud = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "us") objWeatherInfo.envInfo.us = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "up") objWeatherInfo.envInfo.up = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "ur") objWeatherInfo.envInfo.ur = objData.childNodes[0].nodeValue; } //. Location info objElem = xmlDoc.getElementsByTagName("loc")[0]; objWeatherInfo.locationInfo.localId = objElem.attributes.getNamedItem("id").value; aryNodes = objElem.childNodes; len = aryNodes.length; // loc, dnam, tm, lat, lon, sunr, suns, zone for(var i=0;i<len;i++) { var objData = aryNodes[i]; if(objData.nodeName.toLowerCase() == "dnam") objWeatherInfo.locationInfo.name = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "tm") objWeatherInfo.locationInfo.localtime = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "lat") objWeatherInfo.locationInfo.latitue = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "lon") objWeatherInfo.locationInfo.longitude = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "sunr") objWeatherInfo.locationInfo.sunrise = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "suns") objWeatherInfo.locationInfo.sunset = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "zone") objWeatherInfo.locationInfo.zone = objData.childNodes[0].nodeValue; } var len = objConfigPara.locInfo.length; for(var i=0;i<len;i++) { if(objConfigPara.locInfo[i].id == objWeatherInfo.locationInfo.localId) objWeatherInfo.locationInfo.name = objConfigPara.locInfo[i].name; } //. Links objElem = xmlDoc.getElementsByTagName("lnks")[0]; if(objElem.attributes.getNamedItem("type").value == "prmo") { aryNodes = objElem.childNodes; len = aryNodes.length; objWeatherInfo.links = []; for(var i=0;i<len;i++) { var objData = aryNodes[i]; if(objData.nodeName.toLowerCase() == "link") { var objLink = new AniWeatherObj.Link(); var objItems = objData.childNodes; var ilen = objItems.length; for(var j=0;j<ilen;j++) { if(objItems[j].nodeName.toLowerCase() == "l") objLink.link = objItems[j].childNodes[0].nodeValue; else if(objItems[j].nodeName.toLowerCase() == "t") objLink.title = objItems[j].childNodes[0].nodeValue; } objWeatherInfo.links.push(objLink); } } } if(mode & WEATHER_UPDATE_CURRENT) { //. current condition objElem = xmlDoc.getElementsByTagName("cc")[0]; aryNodes = objElem.childNodes; len = aryNodes.length; // locale, form, ut, ud, us, up, ur for(var i=0;i<len;i++) { var objData = aryNodes[i]; if(objData.nodeName.toLowerCase() == "lsup") objWeatherInfo.currentInfo.time = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "obst") objWeatherInfo.currentInfo.position = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "tmp") objWeatherInfo.currentInfo.temp = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "flik") objWeatherInfo.currentInfo.feellike = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "t") objWeatherInfo.currentInfo.condition = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "icon") objWeatherInfo.currentInfo.icon = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "hmid") objWeatherInfo.currentInfo.humid = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "vis") objWeatherInfo.currentInfo.visible = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "uv") { var objItems = objData.childNodes; var ilen = objItems.length; for(var j=0;j<ilen;j++) { if(objItems[j].nodeName.toLowerCase() == "i") objWeatherInfo.currentInfo.uvvalue = objItems[j].childNodes[0].nodeValue; else if(objItems[j].nodeName.toLowerCase() == "t") objWeatherInfo.currentInfo.uvlevel = objItems[j].childNodes[0].nodeValue; } } else if(objData.nodeName.toLowerCase() == "moon") { var objItems = objData.childNodes; var ilen = objItems.length; for(var j=0;j<ilen;j++) { if(objItems[j].nodeName.toLowerCase() == "icon") objWeatherInfo.currentInfo.moonicon = objItems[j].childNodes[0].nodeValue; else if(objItems[j].nodeName.toLowerCase() == "t") objWeatherInfo.currentInfo.moondesc = objItems[j].childNodes[0].nodeValue; } } else if(objData.nodeName.toLowerCase() == "wind") { var objItems = objData.childNodes; var ilen = objItems.length; for(var j=0;j<ilen;j++) { if(objItems[j].nodeName.toLowerCase() == "s") { objWeatherInfo.currentInfo.windspeed = objItems[j].childNodes[0].nodeValue; } if(objItems[j].nodeName.toLowerCase() == "t") objWeatherInfo.currentInfo.winddir = objItems[j].childNodes[0].nodeValue; } } } } if(mode & WEATHER_UPDATE_FORECAST) { //. forcast objElem = xmlDoc.getElementsByTagName("dayf")[0]; aryNodes = objElem.childNodes; len = aryNodes.length; objWeatherInfo.dailyInfo = []; for(var i=0;i<len;i++) { var objData = aryNodes[i]; if(objData.nodeName.toLowerCase() == "lsup" && objWeatherInfo.currentInfo.time.length == 0) objWeatherInfo.currentInfo.time = objData.childNodes[0].nodeValue; else if(objData.nodeName.toLowerCase() == "day") { var dayIdx = parseInt(objData.attributes.getNamedItem("d").value); objWeatherInfo.dailyInfo[dayIdx] = getDayInfo(objData); } } } } }catch(e){ // alert(e.toString()); try{ //. Manual parsing due to Chrome's bug in XMLParser //. Head info objWeatherInfo.locationInfo.name = "UNAVAILABLE"; //. Location info var objVal = manualParserGet(data, '<loc ', '<dnam>').value; objWeatherInfo.locationInfo.localId = manualParserGet(objVal, 'id="', '">').value; objWeatherInfo.locationInfo.name = manualParserGet(data, '<dnam>', '</dnam>').value; //. Links objVal = manualParserGet(data, '<lnks', '</lnks>').value; while(true) { var objLink = manualParserGet(objVal, '<link', '</link>'); if(objLink) { var linkVal = objLink.value; var link = manualParserGet(linkVal, '<l>', '</l>').value; var title = manualParserGet(linkVal, '<t>', '</t>').value; objWeatherInfo.links.push({'title':title, 'link':link}); objVal = objVal.substr(objLink.newpos); } else break; } //. current condition objVal = manualParserGet(data, '<cc>', '</cc>').value; objWeatherInfo.currentInfo.time = manualParserGet(objVal, '<lsup>', '</lsup>').value; objWeatherInfo.currentInfo.temp = manualParserGet(objVal, '<tmp>', '</tmp>').value; objWeatherInfo.currentInfo.condition = manualParserGet(objVal, '<t>', '</t>').value; objWeatherInfo.currentInfo.icon = manualParserGet(objVal, '<icon>', '</icon>').value; objVal = manualParserGet(objVal, '<wind>', '</wind>').value; objWeatherInfo.currentInfo.windspeed = manualParserGet(objVal, '<s>', '</s>').value; objWeatherInfo.currentInfo.winddir = manualParserGet(objVal, '<t>', '</t>').value; //. forcast objWeatherInfo.dailyInfo = []; objVal = manualParserGet(data, '<dayf', '</dayf>').value; if(objVal) { if(objWeatherInfo.currentInfo.time.length == 0) objWeatherInfo.currentInfo.time = manualParserGet(objVal, '<lsup>', '</lsup>').value; while(true) { var objDay = manualParserGet(objVal, '<day', '</day>'); if(objDay) { var dayVal = objDay.value; var objDaily = new AniWeatherObj.DailyWeatherInfo(); objDaily.highTemp = manualParserGet(dayVal, '<hi>', '</hi>').value; objDaily.lowTemp = manualParserGet(dayVal, '<low>', '</low>').value; var partVal = manualParserGet(objVal, 'p="d"', '</part>').value; objDaily.dayicon = manualParserGet(partVal, '<icon>', '</icon>').value; objDaily.daycond = manualParserGet(partVal, '<t>', '</t>').value; objWeatherInfo.dailyInfo.push(objDaily); objVal = objVal.substr(objDay.newpos); } else break; } } }catch(e){ bProcessed = false; } } try{ if(!bProcessed) { queryStatus = 0; setTimeout(function(){ _getWeatherDetails(false, false, null); }, recheckDelay); return; } if((mode & WEATHER_UPDATE_CURRENT) && objWeatherInfo.currentInfo.time.length > 0) { getDateInfo(objWeatherInfo.currentInfo.time); updateTodayCondition(); } weatherHelperString = getWeatherHelperString(); if(displayExtended) _displayExtendedWeather(); var now = new Date(); timeLastCheck = now.getTime(); queryStatus = 2; if(updateStorage) { var name=''; if(mode & WEATHER_UPDATE_FORECAST) name = objWeatherInfo.locationInfo.localId+'.forcast'; else if(mode & WEATHER_UPDATE_CURRENT) name = objWeatherInfo.locationInfo.localId+'.current'; var val = timeLastCheck+'|'+data; if(browserType == BROWSER_FF) setCharPref(name, val); else if(browserType == BROWSER_CHROME) localStorage.setItem(name, val); } updateWeatherInfo(objWeatherInfo.locationInfo.localId == objConfigPara.locInfo[objConfigPara.defaultLocId].id, notify); }catch(e){alert(e.toString());} } function updateWeatherInfo(isDefault, notify) { if(isDefault) { updatePanelIcon(); weatherDefaultString = weatherHelperString; objDefaultWeatherInfo.copyWeatherInfo(objWeatherInfo); } if(browserType == BROWSER_FF) { // setIntPref('locChanged', 0) if(objConfigPara.noticeSpan > 0 && checkIndex == objConfigPara.noticeSpan) { checkIndex = 0; setTimeout(onAutoWeatherNotice, autoNoticeDelay); } } else if(browserType == BROWSER_CHROME) { var idWeatherString; var idChkWeather; if(isDefault) { idWeatherString = 'hiddenWeatherString'; idChkWeather = 'chkWeatherReady'; } else { idWeatherString = 'hiddenOtherWeatherString'; idChkWeather = 'chkOtherWeatherReady'; } var objString = document.getElementById(idWeatherString); objString.setAttribute("value", weatherHelperString); var chkWeather = document.getElementById(idChkWeather); chkWeather.checked = true; if(notify) chkWeather.onclick(); //. TODO: update weather icon. } } function onAutoWeatherNotice() { displayLauncher(getCurDocument(), weatherHelperString, null, true); } function onUpdatePanelIcon(event) { var objPanel = document.getElementById('aniweatherstatus_current'); if(objPanel) { clearInterval(tmSetPanelIcon); tmSetPanelIcon = null; updatePanelIcon(); } } function getTempValue(temp, unit) { var tempUnit = (typeof unit == "undefined") ? objConfigPara.tempUnit : unit; var tempVal = parseInt(temp); if(temp == "N/A") tempVal = ""; else if(tempUnit == 1) tempVal = Math.round(5*(tempVal-32)/9)+' \u00b0C'; else tempVal = tempVal+' \u00b0F'; return tempVal; } function getWindValue(wind) { var windSpeed = ""; var speed = parseInt(wind); if(speed > 0) { if(objConfigPara.windUnit == 1) windSpeed = ", " + Math.round(mph2kmh * speed) + " " + getLocaleString('display.kmh'); else windSpeed = ", "+ speed + " " + getLocaleString('display.mph'); } return windSpeed; } function getElemHelper(id) { return document.getElementById(id); } function updateGraphIcons() { getElemHelper('aniweatherpanel_national').style.display = (objConfigPara.graphLevel['national'].show == 1) ? "block" : "none"; getElemHelper('aniweatherpanel_vapor').style.display = (objConfigPara.graphLevel['vapor'].show == 1) ? "block" : "none"; getElemHelper('aniweatherpanel_radar').style.display = (objConfigPara.graphLevel['radar'].show == 1) ? "block" : "none"; getElemHelper('aniweatherpanel_uv').style.display = (objConfigPara.graphLevel['uv'].show == 1)? "block" : "none"; getElemHelper('aniweatherpanel_pop').style.display = (objConfigPara.graphLevel['pop'].show == 1) ? "block" : "none"; getElemHelper('aniweatherpanel_high').style.display = (objConfigPara.graphLevel['high'].show == 1) ? "block" : "none"; getElemHelper('aniweatherpanel_air').style.display = (objConfigPara.graphLevel['air'].show == 1) ? "block" : "none"; getElemHelper('aniweatherpanel_alert').style.display = (objConfigPara.graphLevel['alert'].show == 1) ? "block" : "none"; } function updatePanelDay(day, dayname, level, icon, desc, temp) { var disp = ""; var baseURL; if(browserType == BROWSER_FF) { baseURL = "chrome://aniweather/skin/conditions/"; disp = "block"; } else if(browserType == BROWSER_CHROME) { baseURL = "chrome-extension://kjehacgbekgldmillhggcabflamgkapc/res/conditions/"; disp = "inline"; } var obj = getElemHelper('aniweatherstatus_'+day); obj.src = baseURL+""+icon+".png"; if(level.showicon == 1) obj.style.display = disp; else obj.style.display = "none"; var strLabel = dayname+": "; if(level.showdesc == 1) { strLabel = strLabel + desc; if(level.showtemp == 1) strLabel = strLabel + ','; } if(level.showtemp == 1) strLabel = strLabel + getTempValue(temp, objConfigPara.tempUnit); getElemHelper('aniweatherpanel_'+day).style.display = (level.show == 1) ? disp : "none"; var obj = getElemHelper('aniweatherlabel_'+day); if(browserType == BROWSER_FF) obj.value = strLabel; else if(browserType == BROWSER_CHROME) obj.innerHTML = strLabel; // obj.style.display = disp; } function updatePanelIcon() { if(browserType == BROWSER_FF) { var objPanel = getElemHelper('aniweatherstatus_current'); if(!objPanel) { if(tmSetPanelIcon) clearInterval(tmSetPanelIcon); tmSetPanelIcon = setInterval(onUpdatePanelIcon, 500); return; } } try{ updatePanelDay("current", getLocaleString('fullweekday.now'), objConfigPara.displayLevel['current'], objWeatherInfo.currentInfo.icon, objWeatherInfo.currentInfo.condition, objWeatherInfo.currentInfo.temp) var temp = objWeatherInfo.dailyInfo[0].highTemp; if(temp == "N/A") temp = objWeatherInfo.currentInfo.temp; updatePanelDay("today", getLocaleString('fullweekday.today'), objConfigPara.displayLevel['today'], objWeatherInfo.dailyInfo[0].dayicon, objWeatherInfo.dailyInfo[0].daycond, temp) updatePanelDay("2nd", getLocaleString('weekdays.' + objWeatherInfo.dailyInfo[1].weekday.toLowerCase()), objConfigPara.displayLevel['2nd'], objWeatherInfo.dailyInfo[1].dayicon, objWeatherInfo.dailyInfo[1].daycond, objWeatherInfo.dailyInfo[1].highTemp) updatePanelDay("3rd", getLocaleString('weekdays.' + objWeatherInfo.dailyInfo[2].weekday.toLowerCase()), objConfigPara.displayLevel['3rd'], objWeatherInfo.dailyInfo[2].dayicon, objWeatherInfo.dailyInfo[2].daycond, objWeatherInfo.dailyInfo[2].highTemp) updatePanelDay("4th", getLocaleString('weekdays.' + objWeatherInfo.dailyInfo[3].weekday.toLowerCase()), objConfigPara.displayLevel['4th'], objWeatherInfo.dailyInfo[3].dayicon, objWeatherInfo.dailyInfo[3].daycond, objWeatherInfo.dailyInfo[3].highTemp) updatePanelDay("5th", getLocaleString('weekdays.' + objWeatherInfo.dailyInfo[4].weekday.toLowerCase()), objConfigPara.displayLevel['5th'], objWeatherInfo.dailyInfo[4].dayicon, objWeatherInfo.dailyInfo[4].daycond, objWeatherInfo.dailyInfo[4].highTemp) }catch(e){} updateGraphIcons(); if(browserType == BROWSER_FF) { //remove old first-last attribute var objHolder = document.getElementById("aniweather_box"); var aryCanvas = objHolder.getElementsByTagName("awcanvas"); var len = aryCanvas.length; var objFirstVisible = null; var objLastVisible = null; var leftmost = 999999; // Large enough var rightmost = -1; // Small enough for (var i=0; i<len; i++) { var objElem = aryCanvas[i]; if(objElem && objElem.getBoundingClientRect) { var rect = objElem.getBoundingClientRect(); if(objElem.style.display != 'none' && rect.left < leftmost) { leftmost = rect.left; objFirstVisible = objElem; } if(objElem.style.display != 'none' && rect.left > rightmost) { rightmost = rect.left; objLastVisible = objElem; } objElem.removeAttribute("aw-first"); objElem.removeAttribute("aw-last"); } else break; } if(objFirstVisible) objFirstVisible.setAttribute("aw-first", "true"); if(objLastVisible) objLastVisible.setAttribute("aw-last", "true"); } } function getDayInfo(objDay) { var objDaily = new AniWeatherObj.DailyWeatherInfo(); var objItems = objDay.childNodes; var ilen = objItems.length; for(var i=0;i<ilen;i++) { var objItem = objItems[i]; if(objItem.nodeName.toLowerCase() == "hi") objDaily.highTemp = objItem.childNodes[0].nodeValue; else if(objItem.nodeName.toLowerCase() == "low") objDaily.lowTemp = objItem.childNodes[0].nodeValue; else if(objItem.nodeName.toLowerCase() == "sunr") objDaily.sunrise = objItem.childNodes[0].nodeValue; else if(objItem.nodeName.toLowerCase() == "suns") objDaily.sunset = objItem.childNodes[0].nodeValue; else if(objItem.nodeName.toLowerCase() == "part") { if(objItem.attributes.getNamedItem("p").value == "d") { var objParts = objItem.childNodes; var plen = objParts.length; for(var j=0;j<plen;j++) { var objPart = objParts[j]; if(objPart.nodeName.toLowerCase() == "icon") objDaily.dayicon = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "t") objDaily.daycond = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "ppcp") objDaily.dayppcp = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "hmid") objDaily.dayhumid = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "wind") { var objElems = objPart.childNodes; var wlen = objElems.length; for(var k=0;k<wlen;k++) { if(objElems[k].nodeName.toLowerCase() == "s") objDaily.daywindspeed = objElems[k].childNodes[0].nodeValue; else if(objElems[k].nodeName.toLowerCase() == "t") objDaily.daywinddir = objElems[k].childNodes[0].nodeValue; } } } } else if(objItem.attributes.getNamedItem("p").value == "n") { var objParts = objItem.childNodes; var plen = objParts.length; for(var j=0;j<plen;j++) { var objPart = objParts[j]; if(objPart.nodeName.toLowerCase() == "icon") objDaily.nighticon = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "t") objDaily.nightcond = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "ppcp") objDaily.nightppcp = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "hmid") objDaily.nighthumid = objPart.childNodes[0].nodeValue; else if(objPart.nodeName.toLowerCase() == "wind") { var objElems = objPart.childNodes; var wlen = objElems.length; for(var k=0;k<wlen;k++) { if(objElems[k].nodeName.toLowerCase() == "s") objDaily.nightwindspeed = objElems[k].childNodes[0].nodeValue; else if(objElems[k].nodeName.toLowerCase() == "t") objDaily.nightwinddir = objElems[k].childNodes[0].nodeValue; } } } } } } return objDaily; } function updateTodayCondition() { // if(objWeatherInfo.dailyInfo[0].highTemp == "N/A") // objWeatherInfo.dailyInfo[0].highTemp = objWeatherInfo.dailyInfo[0].lowTemp; if(objWeatherInfo.dailyInfo[0].daycond == "N/A") { objWeatherInfo.passToday = true; objWeatherInfo.dailyInfo[0].daycond = objWeatherInfo.currentInfo.condition; } else objWeatherInfo.passToday = false; if(objWeatherInfo.dailyInfo[0].dayicon == "25" || objWeatherInfo.dailyInfo[0].dayicon == "44") // N/A objWeatherInfo.dailyInfo[0].dayicon = objWeatherInfo.currentInfo.icon; if(objWeatherInfo.dailyInfo[0].daywindspeed == "N/A") objWeatherInfo.dailyInfo[0].daywindspeed = objWeatherInfo.currentInfo.windspeed; if(objWeatherInfo.dailyInfo[0].daywinddir == "N/A") objWeatherInfo.dailyInfo[0].daywinddir = objWeatherInfo.currentInfo.winddir; if(objWeatherInfo.dailyInfo[0].dayhumid == "N/A") objWeatherInfo.dailyInfo[0].dayhumid = objWeatherInfo.currentInfo.humid; } function getCurDocument() { var doc = null; if(browserType == BROWSER_FF) { doc = gBrowser.selectedBrowser.contentDocument; } else if(browserType == BROWSER_CHROME) { doc = document; } var aryFrames = doc.getElementsByTagName('frame'); var len = aryFrames.length; var maxArea = 0; var maxId = -1; for(var i=0;i<len;i++) { var docFrame = aryFrames[i].contentWindow.document; var wndFrame = GetClientWindow(docFrame); var width = docFrame.documentElement.clientWidth; var height = docFrame.documentElement.clientHeight; var left = aryFrames[i].offsetLeft; var top = aryFrames[i].offsetTop; if(maxArea < width*height) { maxArea = width*height; maxId = i; } } if(maxId != -1) { doc = aryFrames[maxId].contentWindow.document; } return doc; } function GetClientWindow(doc) { if(browserType == BROWSER_FF) { var wndClient = null; if( document && document.commandDispatcher && document.commandDispatcher.focusedWindow && document.commandDispatcher.focusedWindow.toString() != "[object ChromeWindow]") wndClient = document.commandDispatcher.focusedWindow; else if(doc && doc.defaultView) wndClient = doc.defaultView; return wndClient; } else { if(doc && typeof doc.defaultView != "undefined") return doc.defaultView; return window; } } function getPixel(pxl) { return pxl + ((browserType == BROWSER_IE) ? "" : "px"); } function getClientRect(doc, win) { var width = 0; var height = 0; var left = 0; var top = 0; if(win && win.innerWidth) { width = win.innerWidth; height = win.innerHeight; } else if( doc.body && ( doc.body.clientWidth || doc.body.clientHeight ) ) { width = doc.body.clientWidth; height = doc.body.clientHeight; } else if(doc && doc.documentElement && doc.documentElement.clientWidth && documentdoc.clientHeight) { width = doc.documentElement.clientWidth; height = doc.documentElement.clientHeight; } left = win.pageXOffset ? win.pageXOffset : doc.documentElement ? doc.documentElement.scrollLeft : doc.body ? doc.body.scrollLeft : 0; top = win.pageYOffset ? win.pageYOffset : doc.documentElement ? doc.documentElement.scrollTop : doc.body ? doc.body.scrollTop : 0; return {'left': left, 'top':top, 'width':width, 'height':height}; } function setOpacity(style, value) { if(browserType == BROWSER_IE) style.filter = "alpha(opacity = "+value+");"; else style.opacity = value*0.01; } function removeWeather(removeMini, removeExtended) { var doc = getCurDocument(); var status = -1; var objLauncher = doc.getElementById(weatherLauncherId); if(objLauncher) doc.body.removeChild(objLauncher); if(removeExtended) { var divExtendedHolder = doc.getElementById(extendedHolderId); if(divExtendedHolder) { doc.body.removeChild(divExtendedHolder); status = 0; } } if(removeMini) { var divMiniHolder = doc.getElementById(miniHolderId); if(divMiniHolder) doc.body.removeChild(divMiniHolder); } return status; } function getWeatherHelperString() { var strParas = ''; var windspeed = getWindValue(objWeatherInfo.currentInfo.windspeed); /* strParas = 'city='+objWeatherInfo.locationInfo.name+'&iconbase='+iconBaseUrl+'&locid='+objWeatherInfo.locationInfo.localId+'&nowtemp='+objWeatherInfo.currentInfo.temp+'&nowcond='+objWeatherInfo.currentInfo.condition+'&wind=Wind '+objWeatherInfo.currentInfo.winddir+windspeed+'&nowicon='+objWeatherInfo.currentInfo.icon+'&unit='+objConfigPara.tempUnit+','+objConfigPara.windUnit+'&vis='+objWeatherInfo.currentInfo.visible+'&hum='+objWeatherInfo.currentInfo.humid+'&uv='+objWeatherInfo.currentInfo.uvvalue+' ('+objWeatherInfo.currentInfo.uvlevel+')'+'&dates='+objWeatherInfo.dates+","+'&weekdays='+objWeatherInfo.days+'&winds='+objWeatherInfo.dailyInfo[0].daywindspeed+','+objWeatherInfo.dailyInfo[1].daywindspeed+','+objWeatherInfo.dailyInfo[2].daywindspeed+','+objWeatherInfo.dailyInfo[3].daywindspeed+','+objWeatherInfo.dailyInfo[4].daywindspeed+'&humids='+objWeatherInfo.dailyInfo[0].dayhumid+','+objWeatherInfo.dailyInfo[1].dayhumid+','+objWeatherInfo.dailyInfo[2].dayhumid+','+objWeatherInfo.dailyInfo[3].dayhumid+','+objWeatherInfo.dailyInfo[4].dayhumid+'&ppcps='+objWeatherInfo.dailyInfo[0].dayppcp+','+objWeatherInfo.dailyInfo[1].dayppcp+','+objWeatherInfo.dailyInfo[2].dayppcp+','+objWeatherInfo.dailyInfo[3].dayppcp+','+objWeatherInfo.dailyInfo[4].dayppcp+'&lows='+objWeatherInfo.dailyInfo[0].lowTemp+','+objWeatherInfo.dailyInfo[1].lowTemp+','+objWeatherInfo.dailyInfo[2].lowTemp+','+objWeatherInfo.dailyInfo[3].lowTemp+','+objWeatherInfo.dailyInfo[4].lowTemp+'&highs='+objWeatherInfo.dailyInfo[0].highTemp+','+objWeatherInfo.dailyInfo[1].highTemp+','+objWeatherInfo.dailyInfo[2].highTemp+','+objWeatherInfo.dailyInfo[3].highTemp+','+objWeatherInfo.dailyInfo[4].highTemp+'&conditions='+objWeatherInfo.dailyInfo[0].daycond+','+objWeatherInfo.dailyInfo[1].daycond+','+objWeatherInfo.dailyInfo[2].daycond+','+objWeatherInfo.dailyInfo[3].daycond+','+objWeatherInfo.dailyInfo[4].daycond+'&codes='+objWeatherInfo.dailyInfo[0].dayicon+','+objWeatherInfo.dailyInfo[1].dayicon+','+objWeatherInfo.dailyInfo[2].dayicon+','+objWeatherInfo.dailyInfo[3].dayicon+','+objWeatherInfo.dailyInfo[4].dayicon+'&linktitles='+objWeatherInfo.links[0].title+','+objWeatherInfo.links[1].title+','+objWeatherInfo.links[2].title+','+objWeatherInfo.links[3].title+'&linkurls='+escape(objWeatherInfo.links[0].link)+','+escape(objWeatherInfo.links[1].link)+','+escape(objWeatherInfo.links[2].link)+','+escape(objWeatherInfo.links[3].link); */ var mp = objWeatherInfo.currentInfo.moonicon; var strPhases = mp; for(var i=0;i<4;i++) { mp++; if(mp >= 30) mp -= 30; strPhases = strPhases +','+ mp; } strParas = 'city='+objWeatherInfo.locationInfo.name+'&iconbase='+iconBaseUrl+'&locid='+objWeatherInfo.locationInfo.localId+'&nowtemp='+objWeatherInfo.currentInfo.temp+'&nowcond='+objWeatherInfo.currentInfo.condition+'&wind=Wind '+objWeatherInfo.currentInfo.winddir+windspeed+'&nowicon='+objWeatherInfo.currentInfo.icon+'&unit='+objConfigPara.tempUnit+','+objConfigPara.windUnit+'&vis='+objWeatherInfo.currentInfo.visible+'&hum='+objWeatherInfo.currentInfo.humid+'&uv='+objWeatherInfo.currentInfo.uvvalue+' ('+objWeatherInfo.currentInfo.uvlevel+')'+'&dates='+objWeatherInfo.dates+","+'&weekdays='+objWeatherInfo.days+'&winds='+objWeatherInfo.dailyInfo[0].daywindspeed+','+objWeatherInfo.dailyInfo[1].daywindspeed+','+objWeatherInfo.dailyInfo[2].daywindspeed+','+objWeatherInfo.dailyInfo[3].daywindspeed+','+objWeatherInfo.dailyInfo[4].daywindspeed+'&humids='+objWeatherInfo.dailyInfo[0].dayhumid+','+objWeatherInfo.dailyInfo[1].dayhumid+','+objWeatherInfo.dailyInfo[2].dayhumid+','+objWeatherInfo.dailyInfo[3].dayhumid+','+objWeatherInfo.dailyInfo[4].dayhumid+'&ppcps='+objWeatherInfo.dailyInfo[0].dayppcp+','+objWeatherInfo.dailyInfo[1].dayppcp+','+objWeatherInfo.dailyInfo[2].dayppcp+','+objWeatherInfo.dailyInfo[3].dayppcp+','+objWeatherInfo.dailyInfo[4].dayppcp+'&lows='+objWeatherInfo.dailyInfo[0].lowTemp+','+objWeatherInfo.dailyInfo[1].lowTemp+','+objWeatherInfo.dailyInfo[2].lowTemp+','+objWeatherInfo.dailyInfo[3].lowTemp+','+objWeatherInfo.dailyInfo[4].lowTemp+'&highs='+objWeatherInfo.dailyInfo[0].highTemp+','+objWeatherInfo.dailyInfo[1].highTemp+','+objWeatherInfo.dailyInfo[2].highTemp+','+objWeatherInfo.dailyInfo[3].highTemp+','+objWeatherInfo.dailyInfo[4].highTemp+'&conditions='+objWeatherInfo.dailyInfo[0].daycond+','+objWeatherInfo.dailyInfo[1].daycond+','+objWeatherInfo.dailyInfo[2].daycond+','+objWeatherInfo.dailyInfo[3].daycond+','+objWeatherInfo.dailyInfo[4].daycond+'&codes='+objWeatherInfo.dailyInfo[0].dayicon+','+objWeatherInfo.dailyInfo[1].dayicon+','+objWeatherInfo.dailyInfo[2].dayicon+','+objWeatherInfo.dailyInfo[3].dayicon+','+objWeatherInfo.dailyInfo[4].dayicon+'&linkidx='+aryTWCLinks[objWeatherInfo.links[0].title]+','+aryTWCLinks[objWeatherInfo.links[1].title]+','+aryTWCLinks[objWeatherInfo.links[2].title]+','+aryTWCLinks[objWeatherInfo.links[3].title]+'&phases='+strPhases; strParas = encodeURIComponent(strParas); return strParas; } function _displayExtendedWeather(dispMode, graphName) { var dispMode = (typeof dispMode == "undefined") ? 0 : dispMode; var graphName = (typeof graphName == "undefined") ? "vapor" : graphName; removeWeather(true, true); var doc = getCurDocument(); var wnd = GetClientWindow(doc); var shift = 64; toggleTopmostFlash(doc, false); var rectClient = getClientRect(doc, wnd); var divExtendedHolder = doc.getElementById(extendedHolderId); if(divExtendedHolder) { divExtendedHolder.style.left = getPixel(0); divExtendedHolder.style.top = getPixel(0); } else { divExtendedHolder = doc.createElement("div"); divExtendedHolder.style.padding="0px"; divExtendedHolder.style.margin="0px"; divExtendedHolder.style.border = "none"; divExtendedHolder.style.backgroundColor="transparent"; divExtendedHolder.style.left = getPixel(0); divExtendedHolder.style.top = getPixel(0); divExtendedHolder.style.width = (rectClient.width) + "px"; divExtendedHolder.style.height = (rectClient.height) + "px"; divExtendedHolder.style.display = "block"; divExtendedHolder.style.position = (browserType == BROWSER_IE) ? "absolute" : "fixed"; divExtendedHolder.id = extendedHolderId; var divExtendedCanvas = doc.createElement("div"); divExtendedCanvas.style.border = "1px solid #0B48A4"; divExtendedCanvas.style.backgroundColor=fadingColor; divExtendedCanvas.style.padding="0px"; divExtendedCanvas.style.margin="0px"; divExtendedCanvas.style.position = "absolute"; divExtendedCanvas.style.display = "block"; divExtendedCanvas.style.left = getPixel(0); divExtendedCanvas.style.top = getPixel(0); divExtendedCanvas.style.width = rectClient.width +"px"; divExtendedCanvas.style.height = rectClient.height + "px"; divExtendedCanvas.style.zIndex = "9999"; divExtendedCanvas.id = extendedWeatherCanvasId; setOpacity(divExtendedCanvas.style, fadingRatio); divExtendedWeather = doc.createElement("div"); divExtendedWeather.style.border = "none"; divExtendedWeather.style.backgroundColor="transparent"; divExtendedWeather.style.position = "absolute"; divExtendedWeather.style.display = "block"; var strSwitch = ''; if(dispMode == 0) { /* divExtendedWeather.style.left = getPixel((rectClient.width - extendedWidth) / 2); divExtendedWeather.style.top = getPixel((rectClient.height - extendedHeight) / 2 - shift); divExtendedWeather.style.width = extendedWidth +"px"; divExtendedWeather.style.height = extendedHeight + "px"; */ var deltaH = (rectClient.height - extendedHeight) / 2; divExtendedWeather.style.width = (rectClient.width) +"px"; divExtendedWeather.style.height = (extendedHeight + deltaH - shift) + "px"; divExtendedWeather.style.left = "0px"; divExtendedWeather.style.top = "0px"; // getPixel((rectClient.height - CANVAS_HEIGHT) / 2 - shift); strSwitch = '<a class="st-taf" href="javascript:;" style="border:0;padding:0;margin:0;"><img id="aniWeatherGraphic" title="Graphic Reports" style="border:0;padding:0;margin:0 32px 0 0;display:inline;" width="64" height="64" src="'+weatherMediaBase+'res/radarmap.png" /></a>'; } else { var deltaH = (rectClient.height - CANVAS_HEIGHT) / 2; divExtendedWeather.style.width = (rectClient.width) +"px"; divExtendedWeather.style.height = (CANVAS_HEIGHT + deltaH - shift) + "px"; divExtendedWeather.style.left = "0px"; divExtendedWeather.style.top = "0px"; // getPixel((rectClient.height - CANVAS_HEIGHT) / 2 - shift); strSwitch = '<a class="st-taf" href="javascript:;" style="border:0;padding:0;margin:0;"><img id="aniWeatherAnimated" title="Animated 5-Day Forecast" style="border:0;padding:0;margin:0 32px 0 0;display:inline;" width="64" height="64" src="'+weatherMediaBase+'res/animated.png" /></a>'; } divExtendedWeather.style.zIndex = "10000"; divExtendedWeather.id = extendedWeatherId; var strParas = weatherHelperString; if(browserType == BROWSER_FF) strParas = _attachLocIds(strParas); var aryParas = strParas.split('&'); var len = aryParas.length; var aryCities = []; var aryLocIds = []; var strVal; for(var i=len-1;i>=0;i--) { strVal = aryParas[i]; var pos = strVal.indexOf('cities='); if(pos >= 0) { strVal = strVal.substr(7); aryCities = strVal.split('|'); } strVal = aryParas[i]; var pos = strVal.indexOf('locids='); if(pos >= 0) { strVal = strVal.substr(7); aryLocIds = strVal.split('|'); } } len = Math.min(aryCities.length, aryLocIds.length); if(extendedWidth < 480) len = 2; var strMoreCities = ""; for(var i=0;i<len;i++) { var city = aryCities[i]; var pos = city.indexOf(','); if(pos > 0) city = city.substr(0, pos); strMoreCities += '<a style="font-family: Verdana, Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px; color:#ffffff; margin:8px;" href="javascript:;" id="'+weatherCityLinkId+''+aryLocIds[i]+ '" >' +city+'</a>'; } var strRecomm = ''; if(browserType == BROWSER_FF) { strRecomm = '<a class="st-taf" href="javascript:;" onclick="return false;" style="border:0;padding:0;margin:0;"><img title="Tell your friends about AniWeather" style="border:0;padding:0;margin:0;display:inline;" width="64" height="64" src="'+weatherMediaBase+'res/share.png" onmouseout="STTAFFUNC.hideHoverMap(this)" onmouseover="STTAFFUNC.showHoverMap(this, \'2009053018259\', \'http://www.aniweather.com\', \'AniWeather: Animated Weather + Any Weather\')" onclick="STTAFFUNC.cw(this, {id:\'2009053018259\', link: \'http://www.aniweather.com\', title: \'AniWeather: Animated Weather + Any Weather\' });"/></a>'; } else if(browserType == BROWSER_CHROME) { strRecomm = '<a class="st-taf" href="http://www.aniweather.com/?sr=1'+'" target="_blank" style="border:0;padding:0;margin:0;"><img title="Tell your friends about AniWeather" style="border:0;padding:0;margin:0;display:inline;" width="64" height="64" src="'+weatherMediaBase+'res/share.png" /></a>'; } var closeLeft; var closeTop; var closeSize = 32; /* if(dispMode == 0) { var closeSize = 32; closeSize = closeSize*extendedWidth/640; closeLeft = rectClient.width-closeSize-4; closeTop = (displayMode == 0) ? 28 : 10; closeTop = closeTop*extendedWidth/640; } else { */ var fileName = (displayMode == 0) ? 'weather7.swf' : 'weather3.swf'; var strWeatherContent = (dispMode == 0) ? //. '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+extendedWidth+'" height="'+extendedHeight+'"><param name="movie" value="'+weatherMediaBase+'media/'+fileName+'" /><param name="FlashVars" value="'+strParas+'" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/'+fileName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+strParas+'" type="application/x-shockwave-flash" width="'+extendedWidth+'" height="'+extendedHeight+'" wmode="transparent"></embed></object>' : '<iframe type="content" style="width:100%; height:100%;border:none; visibility:hidden" id="frmWeatherContent" scrolling="no" allowtransparency="true" src="'+weatherSiteBase+'showaw2.html?width='+extendedWidth+'&ch='+parseInt(divExtendedWeather.style.height)+'&p='+strParas+'" ></iframe>' : '<iframe type="content" style="width:100%; height:100%;border:none; visibility:hidden" id="frmGraphContent" scrolling="no" allowtransparency="true" src="'+weatherSiteBase+'noaa/noaa_index.html?height='+parseInt(divExtendedWeather.style.height)+'&ani=0&graph='+graphName+'" ></iframe>'; // closeSize = closeSize*extendedWidth/640; closeLeft = (rectClient.height > doc.body.offsetHeight) ? rectClient.width-closeSize-4 : rectClient.width-closeSize-20; closeTop = 4; divExtendedWeather.innerHTML = '<div style="display:block; position:fixed; left:0px; top:0px; padding:4px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold;"><a style="text-decoration:none; color:#ffffff;" href="http://www.aniweather.com/" target="_blank"><img align="absmiddle" id="aniweatherLogo" style="border:0px; padding:0px; margin:0px; cursor:pointer; " width="32" height="32" src="'+weatherMediaBase+'res/aniweather_logo_32.png" > AniWeather</a></div><img id="aniweatherExtendedClose" style="border:0px; padding:0px; margin:0px; cursor:pointer;display:block; position:fixed; left:'+closeLeft+'px; top:'+closeTop+'px;" width="'+closeSize+'" height="'+closeSize+'" src="'+weatherMediaBase+'res/big_close.png" >'+strWeatherContent+'<br /><div align="center" style="padding:0px;margin:0px;">'+strMoreCities+'</div><div id="'+weatherDashboardId+'" style="padding-top:16px;" align="center"><script type="text/javascript" src="http://cdn.socialtwist.com/2009053018259/script.js"></script><a class="st-taf" href="'+weatherSiteBase+''+ 'locale/' + localeId +'/' + settingPageName + '#settings" target="_blank" style="border:0;padding:0;margin:0;"><img title="Settings" style="border:0;padding:0;margin:0 32px 0 32px;display:inline;" width="64" height="64" src="'+weatherMediaBase+'res/setting.png" /></a>'+strRecomm+'<a class="st-taf" href="'+weatherSiteBase+''+feedbackPageName+'" style="border:0;padding:0;margin:0;" target="_blank"><img title="Feedback" style="border:0;padding:0;margin:0 32px 0 32px;display:inline;" width="64" height="64" src="'+weatherMediaBase+'res/feedback.png" /></a>'+strSwitch+'</div>'; divExtendedHolder.appendChild(divExtendedCanvas); divExtendedHolder.appendChild(divExtendedWeather); doc.body.appendChild(divExtendedHolder, false); setEventListener(divExtendedHolder, 'click', onExtendedHolderClicked, false); var objClose = doc.getElementById('aniweatherExtendedClose'); setEventListener(objClose, 'click', onExtendedClose, false); var objGraphic = doc.getElementById('aniWeatherGraphic'); setEventListener(objGraphic, 'click', onAniWeatherGraphic, false); var objAnimated = doc.getElementById('aniWeatherAnimated'); setEventListener(objAnimated, 'click', onAniWeatherAnimated, false); for(var i=0;i<len;i++) { var strId = weatherCityLinkId+aryLocIds[i]; var objCity = doc.getElementById(strId); if(objCity) setEventListener(objCity, 'click', onCityRequest, false); } if(browserType == BROWSER_FF) { var appcontent = document.getElementById("appcontent"); // browser if(appcontent) { setEventListener(appcontent, 'keydown', smartKeyPress, false); } } else if(browserType == BROWSER_CHROME) { setEventListener(doc, 'keydown', smartKeyPress, false); } var objFrame = doc.getElementById(dispMode == 0 ? 'frmWeatherContent' : 'frmGraphContent'); if(objFrame) setTimeout(function(){objFrame.style.visibility = "visible"; }, 500); } function onAniWeatherGraphic(event) { _displayExtendedWeather(1); } function onAniWeatherAnimated(event) { _displayExtendedWeather(0); } function onExtendedClose(event) { var doc = getDocumentByEvent(event); var obj = getObjectByEvent(event); if(obj && obj.id == "aniweatherExtendedClose") { removeWeather(true, true); toggleTopmostFlash(doc, true); } } function onCityRequest(event) { var doc = getDocumentByEvent(event); var obj = getObjectByEvent(event); var strId = obj.id; var pos = strId.indexOf(weatherCityLinkId); if(pos == 0) { var locid = strId.substr(weatherCityLinkId.length); if(browserType == BROWSER_CHROME) { if(curPort) curPort.postMessage({'purpose':'getweather', 'id':locid}); } else _getWeatherDetails(false, true, null, locid); } } function toggleTopmostFlash(doc, display) { aryFlash = doc.getElementsByTagName('object'); var len = aryFlash.length; for(var i=0;i<len;i++) { var objFlash = aryFlash[i]; objFlash.style.visibility = display ? "visible" : "hidden"; } aryFlash = doc.getElementsByTagName('embed'); var len = aryFlash.length; for(var i=0;i<len;i++) { var objFlash = aryFlash[i]; objFlash.style.visibility = display ? "visible" : "hidden"; } } function getObjectByEvent(event) { if(browserType == BROWSER_IE) { var objtype = typeof event.srcElement; if(objtype.toLowerCase() != "unknown") return event.srcElement; else return null; } else if(browserType == BROWSER_FF) return event.originalTarget; else if(browserType == BROWSER_CHROME) return event.srcElement; } function onExtendedHolderClicked(event) { var x = event.clientX; var y = event.clientY; var doc = getCurDocument(); var obj = getObjectByEvent(event); var escape = false; while(true) { if(obj.id && obj.id == extendedWeatherId) { escape = true; break; } if(obj.parentNode) obj = obj.parentNode; else break; } if(!escape) { removeWeather(true, true); toggleTopmostFlash(doc, true); } } } this.displayExtendedWeather = function(data, mode, graphName) { var mode = (typeof mode == "undefined") ? 0 : mode; if(data != null) weatherHelperString = data; _displayExtendedWeather(mode, graphName); } function onDisplayExtendedWeather(event) { _displayExtendedWeather(); } function onMoreGraph(event) { _displayExtendedWeather(1, currentGraphId); } function resetLauncher() { removeLauncher(docLauncher); docLauncher = null; launcherIdx = 0; currentReportId = ""; if(tmLauncherAnimation) { clearInterval(tmLauncherAnimation); tmLauncherAnimation = null; } } function removeLauncher(doc) { if(doc) { var objLauncher = doc.getElementById(weatherLauncherId); if(objLauncher) doc.body.removeChild(objLauncher); } } function displayLauncher(doc, data, info, ani, force, anchor) { if(typeof doc.body == "undefined") return; if(doc.defaultView.innerWidth < MIN_LAUNCHER_WIDTH || doc.defaultView.innerHeight < MIN_LAUNCHER_HEIGHT) return; //. Image if (!doc.body.hasChildNodes() || (doc.body.childNodes.length == 1 && doc.body.childNodes[0].nodeName.toLowerCase() == "img")) { return; } var isGraphic = (currentReportId != "" && typeof lstReportId[currentReportId] == "undefined"); if(isGraphic) currentGraphId = currentReportId; var force = force ? force : false; if(doc != docLauncher || force) //. remove the launcher in other doc resetLauncher(); var ani = isGraphic ? false : (ani ? ani : false); var info = (typeof info == "undefined") ? null : info; var objLauncher = doc.getElementById(weatherLauncherId); var objExtended = doc.getElementById(extendedHolderId); if(objLauncher || objExtended) return; var wnd = GetClientWindow(doc); var rectClient = getClientRect(doc, wnd); var launcherMargin = (browserType == BROWSER_FF) ? 12 : 24; if(data && data.length > 0) { weatherHelperString = data; } else weatherHelperString = weatherDefaultString; var bLargeNotice = (!isGraphic && info != null && info.dayname.toLowerCase() != "now"); var bkImg; var noticeH; if(bLargeNotice){ bkImg = 'noticebkl2.png'; noticeH = noticeMoreHeight; } else{ bkImg = 'noticebk4.png'; noticeH = noticeHeight; } var launcherWidth = isGraphic ? objConfigPara.graphPreviewWidth : noticeWidth; var launcherHeight = isGraphic ? Math.floor(objConfigPara.graphPreviewWidth * defaultGraphHeight / defaultGraphWidth): noticeH; var shift = ani ? launcherHeight/2 - 16 : launcherHeight; var launcherLeft = 4; var scrollWidth = (rectClient.height > doc.body.offsetHeight) ? 12 : 28; if(typeof anchor == "undefined") { // if(browserType == BROWSER_FF) launcherLeft = rectClient.width - launcherWidth - scrollWidth; // else if(browserType == BROWSER_CHROME) // launcherLeft = launcherMargin; } else launcherLeft = Math.min(rectClient.width - launcherWidth - scrollWidth, Math.max(0, anchor - launcherWidth/2 - scrollWidth)); var divWeatherLauncher = doc.createElement("div"); divWeatherLauncher.style.border = "none"; if(isGraphic) { divWeatherLauncher.style.backgroundColor = "#222222"; divWeatherLauncher.style.padding = "0px" divWeatherLauncher.style.border = "solid 1px #888888"; divWeatherLauncher.style.color = "#ffffff"; divWeatherLauncher.style.fontWeight = "bold"; divWeatherLauncher.style.fondSize = "10px"; } else { divWeatherLauncher.style.background= "url("+weatherMediaBase+"res/"+bkImg+") top left no-repeat"; divWeatherLauncher.style.backgroundColor = "transparent"; divWeatherLauncher.style.padding = "8px"; divWeatherLauncher.style.border = "none"; } var holderId = getCharPref('displayPosition'); var atBottom = (holderId == "status-bar") || ani || (browserType == BROWSER_CHROME); divWeatherLauncher.style.position = "fixed"; divWeatherLauncher.style.border = "none"; divWeatherLauncher.style.margin = "0"; divWeatherLauncher.style.display = "block"; divWeatherLauncher.style.left = getPixel(launcherLeft); divWeatherLauncher.style.top = atBottom ? getPixel(rectClient.height - shift - launcherMargin) : "4px"; divWeatherLauncher.style.width = launcherWidth +"px"; divWeatherLauncher.style.height = launcherHeight + "px"; divWeatherLauncher.style.zIndex = "9999"; // divWeatherLauncher.style.cursor = "pointer"; divWeatherLauncher.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif"; divWeatherLauncher.id = weatherLauncherId; var uv = ''; var ppcp = ''; if(!isGraphic) { if(info == null) { // Get current condition info = new AniWeatherObj.GeneralWeather(); var strParas = decodeURIComponent(weatherHelperString); var aryData = strParas.split('&'); info.dayname = "Now"; info.locname = aryData[0].split('=')[1]; var temp = aryData[3].split('=')[1]; info.cond = aryData[4].split('=')[1]; info.windcond = aryData[5].split('=')[1]; info.icon = aryData[6].split('=')[1]; var units = aryData[7].split('=')[1]; info.tempval = getTempValue(temp, parseInt(units.split(',')[0])); info.vis = aryData[8].split('=')[1]; info.humid = aryData[9].split('=')[1]; info.uv = aryData[10].split('=')[1]; info.ppcp = ""; // aryData[11].split('=')[1]; var len = aryData.length; for(var i=0;i<len;i++) { var aryVal = aryData[i].split('='); if(aryVal[0].toLowerCase() == "phases") { info.moonphase = aryVal[1].split(',')[0]; } } } if(info.uv != '') uv = "<br />" + getLocaleString('display.uv') + ": " + info.uv; if(info.ppcp != '') ppcp = "<br />" + getLocaleString('display.pop') + ": " + info.ppcp; } var strDayObj; var strNightObj; if(info.useMiniFrame == 0) { var fileName = "weather5s.swf"; var params = "nowicon="+info.icon+"&phase="+info.moonphase; var width = bLargeNotice ? traySmallWidth : trayWidth; var height = trayHeight * width / trayWidth; if(bLargeNotice) { strDayObj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+weatherMediaBase+'media/'+fileName+'" /><param name="FlashVars" value="'+params+'" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/'+fileName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+params+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed></object>'; params = "nowicon="+info.nighticon+"&phase="+info.moonphase; strNightObj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+weatherMediaBase+'media/'+fileName+'" /><param name="FlashVars" value="'+params+'" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/'+fileName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+params+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed></object>'; } else strDayObj = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+weatherMediaBase+'media/'+fileName+'" /><param name="FlashVars" value="'+params+'" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/'+fileName+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="'+params+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" wmode="transparent"></embed></object>'; } else { if(bLargeNotice) { strDayObj = '<iframe type="content" style="width:100%; height:100%;border:none;padding:0; margin:0;" id="frmWeatherContent" scrolling="no" allowtransparency="true" src="'+weatherSiteBase+'showmini.html?width='+traySmallWidth+'&icon='+info.icon+'&phase='+info.moonphase+'" ></iframe>'; strNightObj = '<iframe type="content" style="width:100%; height:100%;border:none;padding:0; margin:0;" id="frmWeatherContent" scrolling="no" allowtransparency="true" src="'+weatherSiteBase+'showmini.html?width='+traySmallWidth+'&icon='+info.nighticon+'&phase='+info.moonphase+'" ></iframe>'; } else strDayObj = '<iframe type="content" style="width:100%; height:100%;border:none;padding:0; margin:0;" id="frmWeatherContent" scrolling="no" allowtransparency="true" src="'+weatherSiteBase+'showmini.html?width='+trayWidth+'&icon='+info.icon+'&phase='+info.moonphase+'" ></iframe>'; } var content = ""; if(isGraphic) { var strCtrls = ""; if(false && browserType != BROWSER_FF) strCtrls = ' <a style="color:#ffffff; font-size:12px;font-weight:bold;" href="javascript:;" id="moreAniWeatherGraph">More</a> <a style="color:#ffffff; font-size:12px;font-weight:bold;" href="javascript:;" id="aniweatherLauncherClose">Close</a>'; content = '<div style="padding:0; margin:0; width:100%; height:'+(launcherHeight-20)+'px;" ><iframe type="content" style="border:none; width:100%; height:100%; padding:0; margin:0;" id="frmGraphContent" scrolling="no" allowtransparency="true" src="'+weatherSiteBase+'noaa/graph.html?type='+info.graphId+'&ani='+info.graphAnimation+'&thumb=1&width='+objConfigPara.graphPreviewWidth+'" ></iframe></div><div style="position:absolute;left:0px;top:0px;display:block;width:100%;height:'+(launcherHeight-20)+'px;background-color:transparent;cursor:pointer; border:none;" id="divGraphMask"></div><div align="right" style="margin:0; padding:0; border:none;"><span style="font-size:12px; color:#ffff00;">'+info.graphDesc+'</span> ' +strCtrls+ '</div>'; } else if(bLargeNotice) { content = '<div id="'+ weatherLauncherHolderId + '" style="display:block;position:absolute; top:4px; left:0px; width:'+noticeWidth+'px; cursor:pointer; "><div style="border:none; display:block; position:absolute;left:4px;top:-4px;width:'+traySmallWidth+'px;height:'+traySmallHeight+'px;padding:0px;margin:0px;background-color:transparent;">'+strDayObj+'</div><div style="border:none; display:block; position:absolute;left:4px;top:88px;width:'+traySmallWidth+'px;height:'+traySmallHeight+'px;padding:0px;margin:0px;background-color:transparent;">'+strNightObj+'</div><div style="position:absolute;display:block; left:8px;top:'+(launcherHeight-32)+'px;font-size:12px; border:none; font-weight:bold; color:#ffff33; padding:0px;margin:0px;margin-bottom:2px; "><span id="regionLocName" style="border:none;margin:0;padding:0;">'+info.locname+'</span><span style="color:#22ff22;margin:0px;padding:0px;"> '+FULLWEEKDAY[info.dayname]+'</span></div><div align="left" style="display:block; font-weight:normal; position:absolute;left:'+(traySmallWidth+8)+'px;margin-right:0px;top:8px;width:'+(noticeWidth-traySmallWidth)+'px;height:'+(traySmallHeight-8)+'px;line-height:1.2em; padding:0px;margin:0px;color:#ffffff;font-size:11px;border:none; "><span style="color:#22ff22;margin:0px;padding:0px;"><strong style="color:#22ff22;">'+info.daypart+' </strong>'+info.tempval+'</span><br />'+info.cond+'<br />'+info.windcond+'<br />' + getLocaleString('display.humidity') + ': '+info.humid+uv+ppcp+'<br />' + getLocaleString('display.sunrise') + ': '+info.sunrise+'</div><div align="left" style="display:block; font-weight:normal; position:absolute;left:'+(traySmallWidth+8)+'px;margin-right:0px;top:96px;width:'+(noticeWidth-traySmallWidth)+'px;height:'+(traySmallHeight-8)+'px;line-height:1.2em; padding:0px;margin:0px;color:#ffffff;font-size:11px;border:none; "><span style="color:#22ff22;margin:0px;padding:0px;"><strong style="color:#22ff22;">' + getLocaleString('display.night') + ' </strong>'+info.nighttemp+'</span><br />'+info.nightcond+'<br />'+info.nightwindcond+'<br />' + getLocaleString('display.humidity') + ': '+info.nighthumid+'<br />' + getLocaleString('display.pop') + ': '+info.nightppcp+'<br />' + getLocaleString('display.sunset') + ': '+info.sunset+'</div>'; } else { content = '<div id="'+ weatherLauncherHolderId + '" style="display:block;position:absolute; top:4px; left:0px; width:'+noticeWidth+'px; cursor:pointer;"><div style="border:none; display:block; position:absolute;left:-12px;top:-24px;width:'+trayWidth+'px;height:'+trayHeight+'px;padding:0px;margin:0px;background-color:transparent;">'+strDayObj+'</div><div style="position:absolute;display:block; left:8px;top:'+(trayHeight-44)+'px;font-size:12px; border:none; font-weight:bold; color:#ffff33; padding:0px;margin:0px;margin-bottom:2px; "><span id="regionLocName" style="border:none;margin:0;padding:0;">'+info.locname+'</span><span style="color:#22ff22;margin:0px;padding:0px;"> '+FULLWEEKDAY[info.dayname]+', '+info.tempval+'</span></div><div align="left" style="display:block; font-weight:normal; position:absolute;left:'+(trayWidth-12)+'px;margin-right:0px;top:4px;width:'+(noticeWidth-trayWidth)+'px;height:'+noticeHeight+'px;line-height:1.2em; padding:0px;margin:0px;color:#ffffff;font-size:11px;">'+info.cond+'<br />'+info.windcond+'<br />' + getLocaleString('display.humidity') + ': '+info.humid+uv+ppcp+'</div>'; } divWeatherLauncher.innerHTML = content; doc.body.appendChild(divWeatherLauncher); var locname = info.locname; var divLoc = doc.getElementById('regionLocName'); if(divLoc) { var len = locname.length; while(len > 10 && (divLoc.offsetWidth >= launcherWidth - 100 || divLoc.offsetHeight >= 20) ) { locname = locname.substr(0, len-1); len--; divLoc.innerHTML = locname + ".."; } } var objLauncher = doc.getElementById(weatherLauncherHolderId); setEventListener(objLauncher, 'click', onDisplayExtendedWeather, false); setEventListener(objLauncher, 'mousemove', onLauncherMove, false); var objClose = doc.getElementById("aniweatherLauncherClose"); setEventListener(objClose, 'click', resetLauncher, false); var objMore = doc.getElementById("aniweatherLauncherMore"); setEventListener(objMore, 'click', onDisplayExtendedWeather, false); var objGraph = doc.getElementById("moreAniWeatherGraph"); setEventListener(objGraph, 'click', onMoreGraph, false); var objMask = doc.getElementById("divGraphMask"); setEventListener(objMask, 'click', onMoreGraph, false); if(ani) tmLauncherAnimation = setInterval(animateLauncher, 100); if(tmLauncher) clearTimeout(tmLauncher); if(ani) // || browserType != BROWSER_FF) tmLauncher = setTimeout(resetLauncher, isGraphic ? graphTime : noticeTime); docLauncher = doc; } function _checkWeatherTimer(directReport) { var reportMode; if(typeof directReport == "boolean") reportMode = directReport ? 0 : 1; else reportMode = 2; if(reportMode == 2) checkIndex++; else if(reportMode == 0) checkIndex = objConfigPara.noticeSpan; _getWeatherDetails(false, false, null); // schedule for next check up var now=new Date(); var hour = now.getHours(); var minute = now.getMinutes(); //. Check at the beginning of each hour var moretime = (60-minute)*60000; // 8000; // // updateChromeStatus(now.getSeconds()); setTimeout(_checkWeatherTimer, moretime); } this.checkWeatherTimer = function(counting) { _checkWeatherTimer(counting); } function onLauncherMove(event) { if(tmLauncher) clearTimeout(tmLauncher); tmLauncher = setTimeout(resetLauncher, noticeTime); } function animateLauncher(event) { var doc = getCurDocument(); var objLauncher = doc.getElementById(weatherLauncherId); var nowtop = parseInt(objLauncher.style.top); var move = launcherSpeed + launcherAcce * launcherIdx; if(move <= 0) { launcherIdx = 0; clearInterval(tmLauncherAnimation); tmLauncherAnimation = null; } else { objLauncher.style.top = getPixel(nowtop-move); launcherIdx++; } } this.prepareReportById = function(reportId, anchor, disp) { var disp = (typeof disp == "undefined") ? true : disp; var info = null; var id = lstReportId[reportId]; if(typeof id == "undefined") { var info = new AniWeatherObj.GeneralWeather(); info.graphId = reportId; info.graphDesc = aryGraphInfo[reportId].desc; info.graphAnimation = objConfigPara.graphLevel[reportId].animation; //. Graphic report, not daily report currentReportId = reportId; if(disp) displayLauncher(getCurDocument(), '', info, false, true, anchor); } else { var info = new AniWeatherObj.GeneralWeather(); info.graphId = null; // alert(objDefaultWeatherInfo.locationInfo.name); info.locname = objDefaultWeatherInfo.locationInfo.name; info.cond = (id == 0) ? objDefaultWeatherInfo.currentInfo.condition : objDefaultWeatherInfo.dailyInfo[id-1].daycond; if(id == 1 && objDefaultWeatherInfo.passToday) { info.tempval = objDefaultWeatherInfo.currentInfo.temp; info.daypart = getLocaleString('fullweekday.now'); } else { info.tempval = (id == 0) ? objDefaultWeatherInfo.currentInfo.temp : objDefaultWeatherInfo.dailyInfo[id-1].highTemp ; info.daypart = getLocaleString('display.day'); } info.tempval = getTempValue(info.tempval, objConfigPara.tempUnit); var windspeed = (id == 0) ? objDefaultWeatherInfo.currentInfo.windspeed : objDefaultWeatherInfo.dailyInfo[id-1].daywindspeed; windspeed = getWindValue(windspeed); var winddir = (id == 0) ? objDefaultWeatherInfo.currentInfo.winddir : objDefaultWeatherInfo.dailyInfo[id-1].daywinddir; info.windcond = getLocaleString('display.wind') + ": " + winddir + windspeed; switch(id) { case 0: info.dayname = "Now"; break; case 1: info.dayname = "Today"; break; default: info.dayname = objDefaultWeatherInfo.dailyInfo[id-1].weekday; } info.icon = (id == 0) ? objDefaultWeatherInfo.currentInfo.icon : objDefaultWeatherInfo.dailyInfo[id-1].dayicon; info.vis = (id == 0) ? objDefaultWeatherInfo.currentInfo.visible : ""; info.humid = (id == 0) ? objDefaultWeatherInfo.currentInfo.humid : objDefaultWeatherInfo.dailyInfo[id-1].dayhumid; info.uv = (id == 0) ? objDefaultWeatherInfo.currentInfo.uvvalue +' ('+objDefaultWeatherInfo.currentInfo.uvlevel+')': ""; info.ppcp = (id == 0) ? "" : objDefaultWeatherInfo.dailyInfo[id-1].dayppcp + "%"; if(id > 0) { info.sunrise = objDefaultWeatherInfo.dailyInfo[id-1].sunrise; info.sunset = objDefaultWeatherInfo.dailyInfo[id-1].sunset; info.nighticon = objDefaultWeatherInfo.dailyInfo[id-1].nighticon; info.nightcond = objDefaultWeatherInfo.dailyInfo[id-1].nightcond; info.nighthumid = objDefaultWeatherInfo.dailyInfo[id-1].nighthumid; info.nightppcp = objDefaultWeatherInfo.dailyInfo[id-1].nightppcp + "%"; info.nighttemp = getTempValue(objDefaultWeatherInfo.dailyInfo[id-1].lowTemp, objConfigPara.tempUnit); windspeed = objDefaultWeatherInfo.dailyInfo[id-1].nightwindspeed; windspeed = getWindValue(windspeed); winddir = objDefaultWeatherInfo.dailyInfo[id-1].nightwinddir; info.nightwindcond = getLocaleString('display.wind') + ": " + winddir + windspeed; } info.useMiniFrame = objConfigPara.useMiniFrame; info.width = objConfigPara.weatherWidth; info.height = objConfigPara.weatherHeight; info.fadingRatio = objConfigPara.fadingRatio; info.fadingColor = objConfigPara.fadingColor; info.noticeSpan = objConfigPara.noticeSpan; info.displayMode = objConfigPara.displayMode; info.animate = false; info.moonphase = parseInt(objDefaultWeatherInfo.currentInfo.moonicon) + ((id == 0) ? 0 : (id-1)); if(info.moonphase >= 30) info.moonphase -= 30; displayMode = info.displayMode; extendedWidth = info.width; extendedHeight = DEFAULT_HEIGHT[displayMode]*info.width/DEFAULT_WIDTH; fadingRatio = info.fadingRatio; fadingColor = info.fadingColor; noticeSpan = info.noticeSpan; if(disp && (currentReportId != reportId)) { currentReportId = reportId; displayLauncher(getCurDocument(), '', info, false, true, anchor); } } return info; } this.prepareReport = function(data, info, reportId, anchor, width) { var id = lstReportId[reportId]; if(typeof id == "undefined") { //. Graphic report, not daily report currentReportId = reportId; displayLauncher(getCurDocument(), data, info, false, true, anchor); } else if(currentReportId != reportId) { currentReportId = reportId; displayMode = info.displayMode; extendedWidth = info.width; extendedHeight = DEFAULT_HEIGHT[displayMode]*info.width/DEFAULT_WIDTH; fadingRatio = info.fadingRatio; fadingColor = info.fadingColor; noticeSpan = info.noticeSpan; if(browserType == BROWSER_CHROME) objConfigPara.graphPreviewWidth = width; displayLauncher(getCurDocument(), data, info, info.animate, true, anchor); } // displayLauncher(getCurDocument(), data); } this.cancelReport = function(data) { removeLauncher(getCurDocument()); } this.revokeReport = function() { resetLauncher(); } function _displayTodayWeather() { //. TODO: Add today weather _displayMiniWeather(); } this.displayTodayWeather = function() { _displayTodayWeather(); } function _displayMiniWeather() { removeWeather(false, true); var doc = getCurDocument(); var wnd = GetClientWindow(doc); var rectClient = getClientRect(doc, wnd); var divMiniHolder = doc.getElementById(miniHolderId); if(divMiniHolder) { divMiniHolder.style.left = getPixel(rectClient.width - miniWidth - miniMargin - holderMargin); divMiniHolder.style.top = getPixel(rectClient.height - miniHeight - miniMargin - holderMargin); } else { divMiniHolder = doc.createElement("div"); divMiniHolder.id = miniHolderId; divMiniHolder.style.padding="0px"; divMiniHolder.style.margin="0px"; divMiniHolder.style.backgroundColor="transparent"; divMiniHolder.style.left = getPixel(rectClient.width - miniWidth - miniMargin - holderMargin); divMiniHolder.style.top = getPixel(rectClient.height - miniHeight - miniMargin - holderMargin); divMiniHolder.style.width = (miniWidth + holderMargin) + "px"; divMiniHolder.style.height = (miniHeight + holderMargin) + "px"; divMiniHolder.style.display = "block"; divMiniHolder.style.position = (browserType == BROWSER_IE) ? "absolute" : "fixed"; divMiniCanvas = doc.createElement("div"); divMiniCanvas.style.border = "1px solid #0B48A4"; divMiniCanvas.style.backgroundColor="#115ED1"; divMiniCanvas.style.padding="0px"; divMiniCanvas.style.margin="0px"; divMiniCanvas.style.position = "absolute"; divMiniCanvas.style.display = "block"; divMiniCanvas.style.left = getPixel(0); divMiniCanvas.style.top = getPixel(0); divMiniCanvas.style.width = miniWidth +"px"; divMiniCanvas.style.height = miniHeight + "px"; divMiniCanvas.style.zIndex = "9999"; divMiniCanvas.id = miniWeatherCanvasId; setOpacity(divMiniCanvas.style, 75); divMiniWeather = doc.createElement("div"); divMiniWeather.style.border = "none"; divMiniWeather.style.backgroundColor="transparent"; divMiniWeather.style.position = "absolute"; divMiniWeather.style.display = "block"; divMiniWeather.style.left = getPixel(0); divMiniWeather.style.top = getPixel(0); divMiniWeather.style.width = miniWidth +"px"; divMiniWeather.style.height = miniHeight + "px"; divMiniWeather.style.zIndex = "10000"; divMiniWeather.id = miniWeatherId; divMiniWeather.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+miniWidth+'" height="'+miniHeight+'"><param name="movie" value="'+weatherMediaBase+'media/weathers.swf" /><param name="wmode" value="transparent"><param name="quality" value="high" /><embed src="'+weatherMediaBase+'media/weathers.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+miniWidth+'" height="'+miniHeight+'" wmode="transparent"></embed></object>'; divMiniHolder.appendChild(divMiniCanvas); divMiniHolder.appendChild(divMiniWeather); doc.body.appendChild(divMiniHolder); } } this.displayMiniWeather = function() { _displayMiniWeather(); } function parseXML(text) { var xmlDoc = null; if(browserType == BROWSER_IE) { try //Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(text); } catch(e) { } } else if(browserType == BROWSER_FF || browserType == BROWSER_CHROME) { try //Firefox, Mozilla, Opera, etc. { parser=new DOMParser(); xmlDoc=parser.parseFromString(text,"text/xml"); } catch(e) { return null; } } return xmlDoc; } function setEventListener(obj, evt, func, bubble) { try { if(browserType == BROWSER_IE) { obj.detachEvent('on'+evt, func); obj.attachEvent('on'+evt, func, bubble); } else /// if(browserType == BROWSER_FF) obj.addEventListener(evt, func, bubble); } catch(err) { // alert(err.toString()); } } } AniWeatherObj.showMini = function(event) { AniWeatherBrowserAgent.displayMiniWeather(event); } AniWeatherObj.showToday = function(event) { AniWeatherBrowserAgent.displayTodayWeather(event); } AniWeatherObj.showExtended = function(data) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.displayExtendedWeather(data); } AniWeatherObj.onPrepareReport = function(event) { var obj = event.originalTarget; var seed = 'aniweatherpanel_'; var pos=obj.id.indexOf(seed); var reportid = ""; if(pos == 0) { reportid = obj.id.substr(seed.length); var anchor = event.clientX; var agent = navigator.userAgent.toLowerCase(); if(agent.indexOf("gecko/") >= 0) { var objFlag = document.getElementById('flagReport'); if(objFlag) { objFlag.value = reportid; } var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); var delay = prefManager.getIntPref('extensions.aniweather.previewDelay'); setTimeout(function(){ var objFlag = document.getElementById('flagReport'); if(objFlag && objFlag.value != "") { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.prepareReportById(objFlag.value, anchor); } }, delay); } } } AniWeatherObj.prepareReport = function(data, info, reportid, anchor, width) { var agent = navigator.userAgent.toLowerCase(); if(agent.indexOf("chrome") >= 0) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.prepareReport(data, info, reportid, anchor, width); } } AniWeatherObj.cancelReport = function() { var objFlag = document.getElementById('flagReport'); if(objFlag) { objFlag.value = ''; } if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.cancelReport(); } AniWeatherObj.onPrefSaved = function(status) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.onPrefSaved(status); } AniWeatherObj.onGetChromeSetting = function(value) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.onGetChromeSetting(value); } AniWeatherObj.localIdReady = function(data) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.localIdReady(data); } AniWeatherObj.revokeReport = function() { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.revokeReport(); } AniWeatherObj.getWeatherDetails = function(event) { if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.MainStart(true, false); } else if(navigator.userAgent.toLowerCase().indexOf("gecko/") >= 0) { AniWeatherBrowserAgent.getWeatherDetails(false, true, event); } } AniWeatherObj.updateNow = function() { if(navigator.userAgent.toLowerCase().indexOf("gecko/") >= 0) { AniWeatherBrowserAgent.getWeatherDetails(true, false, null); } } AniWeatherObj.setAniWeather = function() { AniWeatherBrowserAgent.setAniWeather(); } AniWeatherObj.supportAniWeather = function() { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); var strURL = 'http://www.aniweather.com/php/support.php'; gBrowser.selectedTab = gBrowser.addTab(strURL); } AniWeatherObj.onGraphic = function(event, type) { if(event == null || event.button == 0) AniWeatherBrowserAgent.displayExtendedWeather(null, 1, type); } AniWeatherObj.improveAniWeather = function() { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); var strURL = 'http://www.aniweather.com/php/feedback.php'; gBrowser.selectedTab = gBrowser.addTab(strURL); } AniWeatherObj.help = function() { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); var prefManager = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); var buildno = prefManager.getIntPref('extensions.aniweather.buildNo'); var strURL = 'http://www.aniweather.com/php/help.php?ver=' + buildno; gBrowser.selectedTab = gBrowser.addTab(strURL); } AniWeatherObj.tellAFriend = function() { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); var strURL = 'http://www.aniweather.com/?sr=1'; gBrowser.selectedTab = gBrowser.addTab(strURL); } AniWeatherObj.visitAniWeather = function() { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); var strURL = 'http://www.aniweather.com'; gBrowser.selectedTab = gBrowser.addTab(strURL); } AniWeatherObj.visitTWC = function() { var src = "chrome://aniweather/locale/global.properties"; var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] .getService(Components.interfaces.nsIStringBundleService); var Bundle = stringBundleService.createBundle(src); var strURL = 'http://www.weather.com/?par=xoap&site=wx_logo&cm_ven=bd_oap&cm_cat=1106689085&cm_pla=HomePage&cm_ite=Logo'; gBrowser.selectedTab = gBrowser.addTab(strURL); } AniWeatherObj.menuSearch = function(event) { AniWeatherBrowserAgent.menuSearch(event); } AniWeatherObj.searchLocalId = function(name) { if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) { if(!AniWeatherBrowserAgent) AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.searchLocalId(name); } } AniWeatherObj.updateLocationPopup = function(event) { AniWeatherBrowserAgent.updateLocationPopup(event); } AniWeatherObj.hourlyReport = function(event) { AniWeatherBrowserAgent.hourlyReport(event); } AniWeatherObj.tenDaysReport = function(event) { AniWeatherBrowserAgent.tenDaysReport(event); } var AniWeatherBrowserAgent = null; if(navigator.userAgent.toLowerCase().indexOf("gecko/") >= 0) { AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.MainStart(); } else if(navigator.userAgent.toLowerCase().indexOf("chrome") >= 0) { if(window == top) { var port = chrome.extension.connect(); var idstr = document.title.replace(/\s+/g, '')+document.URL.replace(/\s+/g, ''); setTimeout(function(){ port.postMessage({'purpose':'reg', 'id':idstr}); }, 300); port.onMessage.addListener(function(info) { if(info.purpose == 'show') { if(typeof info.info == "undefined" || info.info.graphId == null) AniWeatherObj.showExtended(info.data, info.info); else AniWeatherObj.onGraphic(null, info.info.graphId); } else if(info.purpose == "hook") { AniWeatherBrowserAgent = new AniWeatherObj.BrowserAgent; AniWeatherBrowserAgent.registerPort(port); AniWeatherBrowserAgent.setServerType(info.server); AniWeatherBrowserAgent.MainStart(false, true); } else if(info.purpose == 'prepare') { AniWeatherObj.prepareReport(info.data, info.info, info.reportId, info.anchor, info.width); } else if(info.purpose == 'saved') { AniWeatherObj.onPrefSaved(info.status); } else if(info.purpose == 'setting') { AniWeatherObj.onGetChromeSetting(info.value); } else if(info.purpose == 'locidready') { AniWeatherObj.localIdReady(info.data); } else if(info.purpose == 'revoke') { AniWeatherObj.revokeReport(); } }); } }